{"id":5656,"date":"2018-10-25T23:00:22","date_gmt":"2018-10-26T04:00:22","guid":{"rendered":"http:\/\/www.thejuliagroup.com\/blog\/?p=5656"},"modified":"2018-10-25T23:00:22","modified_gmt":"2018-10-26T04:00:22","slug":"proc-compare-for-validating-sas-code","status":"publish","type":"post","link":"https:\/\/www.thejuliagroup.com\/blog\/proc-compare-for-validating-sas-code\/","title":{"rendered":"PROC COMPARE FOR VALIDATING SAS CODE"},"content":{"rendered":"\n<p>I know people who are so obsessive about testing and validating their code to the point they spend more time on testing it than actually writing it and analyzing the output. I said I know people like that, I didn&#8217;t say I was one of them. However, it is good practice to validate your SAS code and despite false rumors spread by my enemies, I do it sometimes. <\/p>\n\n\n\n<p>Here is a simple example.\u00a0 I believed that using the COMPRESS function with &#8220;l&#8221; for lower case or &#8220;I&#8221; for case-insensitive gave the same results. I wanted to test that. So, I ran two data steps<\/p>\n\n\n\n<p>DATA USE_L;<br\/>set mydata.aztech_pre ;<br\/>q3 = compress(Q3,&#8217;ABCDEFGHIJKLMNOPQRSTUVWXYZ&#8217;,&#8217;l&#8217;);<br\/>q5 = compress(Q5,&#8217;ABCDEFGHIJKLMNOPQRSTUVWXY&#8217;,&#8217;l&#8217;);<\/p>\n\n\n\n<p>&#8230; and a whole bunch more statements like that.<\/p>\n\n\n\n<p>Then, I ran the exact same data step but with an &#8220;I&#8221; instead of an &#8220;l&#8221;\u00a0 .<\/p>\n\n\n\n<p>Finally, I ran a PROC COMPARE step<\/p>\n\n\n\n<p>PROC COMPARE base =USE_L compare=USE_I ;<br\/>Title &#8220;Using l for lowercase vs I for insenstitive&#8221; ;<br\/><br\/><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"498\" height=\"217\" src=\"http:\/\/www.thejuliagroup.com\/blog\/wp-content\/uploads\/2018\/10\/Screen-Shot-2018-10-25-at-8.14.36-PM.png\" alt=\"\" class=\"wp-image-5657\" srcset=\"https:\/\/www.thejuliagroup.com\/blog\/wp-content\/uploads\/2018\/10\/Screen-Shot-2018-10-25-at-8.14.36-PM.png 498w, https:\/\/www.thejuliagroup.com\/blog\/wp-content\/uploads\/2018\/10\/Screen-Shot-2018-10-25-at-8.14.36-PM-300x131.png 300w\" sizes=\"auto, (max-width: 498px) 100vw, 498px\" \/><figcaption><strong>PROC COMPARE RESULTS SHOW NO DIFFERENCES<br\/><\/strong><\/figcaption><\/figure>\n\n\n\n<p>But, hey, maybe PROC COMPARE just doesn&#8217;t work. Is it really removing everything whether it is upper or lower case? To test this, I ran the procedure again comparing the dataset with the compressed results with the original data set.<\/p>\n\n\n\n<p>PROC COMPARE base =mydata.aztech_pre compare=use_I ;<br\/>\nTitle &#8220;Comparing with and without compress function&#8221; ;<\/p>\n\n\n\n<p>The result was a whole lot of output, which I am not going to reproduce here, but some of the most relevant was:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">  Values Comparison Summary                                                      \n                                                                                                                                    \nNumber of Variables Compared with All Observations Equal: 24.                                     \n Number of Variables Compared with Some Observations Unequal: 16.                                  \nNumber of Variables with Missing Value Differences: 10.                                           \nTotal Number of Values which Compare Unequal: 694. <br\/><br type=\"_moz\"\/><\/pre>\n\n\n\n<p>Looking further in the results, I can see comparison of the results for each variable by observation number<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">          ||  q5                                                                              \n           ||  Base Value           Compare Value                                              \n       Obs ||  q5                    q5                                                        \n ________  ||  ____________          ____________                                              \n            ||                                                                                  \n         5  ||  150m                  150                                                       \n         6  ||  42 miles              42                                                        \n        10  ||  one thousand                                                                    \n        12  ||  200 MILES             200       <\/pre>\n\n\n\n<p>So, I can see that the data step is doing what I want, which is removing all of the text from the responses and only leaving numbers. This is important because the next step is comparing the responses to the questions with the answer key and I don&#8217;t want any mismatches to occur because the student wrote &#8216;200 miles&#8217; instead of 200.<\/p>\n\n\n\n<p>In case you are interested, this is the pretest for two games that are used to teach fractions and statistics. <a href=\"http:\/\/www.7generationgames.com\/aztech-the-story-begins\/\">You can find Aztech: The Story Begins here and play it for free, on your iPad , Mac, Windows or Chromebook computer<\/a>.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"360\" height=\"202\" src=\"http:\/\/www.thejuliagroup.com\/blog\/wp-content\/uploads\/2018\/10\/aztech_talking.jpg\" alt=\"Mayan god\" class=\"wp-image-5658\" srcset=\"https:\/\/www.thejuliagroup.com\/blog\/wp-content\/uploads\/2018\/10\/aztech_talking.jpg 360w, https:\/\/www.thejuliagroup.com\/blog\/wp-content\/uploads\/2018\/10\/aztech_talking-300x168.jpg 300w\" sizes=\"auto, (max-width: 360px) 100vw, 360px\" \/><figcaption><a href=\"http:\/\/www.7generationgames.com\/aztech-the-story-begins\/\">Play Aztech<\/a> !<\/figcaption><\/figure>\n\n\n\n<p><a href=\"http:\/\/www.7generationgames.com\/forgotten-trail\/\"><\/a><\/p>\n\n\n\n<p><a href=\"http:\/\/www.7generationgames.com\/forgotten-trail\/\"><\/a><\/p>\n\n\n\n<p><a href=\"http:\/\/www.7generationgames.com\/forgotten-trail\/\">Forgotten Trail can be played in a browser on any Mac, Windows or Chromebook computer.<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I know people who are so obsessive about testing and validating their code to the point they spend more time on testing it than actually writing it and analyzing the output. I said I know people like that, I didn&#8217;t say I was one of them. However, it is good practice to validate your SAS&#8230;<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[9,8],"tags":[],"class_list":["post-5656","post","type-post","status-publish","format-standard","hentry","category-software","category-technology"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/posts\/5656","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/comments?post=5656"}],"version-history":[{"count":1,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/posts\/5656\/revisions"}],"predecessor-version":[{"id":5659,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/posts\/5656\/revisions\/5659"}],"wp:attachment":[{"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/media?parent=5656"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/categories?post=5656"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/tags?post=5656"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}