{"id":5661,"date":"2018-11-18T10:19:29","date_gmt":"2018-11-18T15:19:29","guid":{"rendered":"http:\/\/www.thejuliagroup.com\/blog\/?p=5661"},"modified":"2018-11-18T10:19:29","modified_gmt":"2018-11-18T15:19:29","slug":"quick-sas-debugging-log-logic","status":"publish","type":"post","link":"https:\/\/www.thejuliagroup.com\/blog\/quick-sas-debugging-log-logic\/","title":{"rendered":"Quick SAS debugging: Log + logic"},"content":{"rendered":"\n<p>I was reminded today how useful a SAS log can be, even when it doesn&#8217;t give you any errors. <\/p>\n\n\n\n<p>I&#8217;m analyzing data from a study on educational technology in rural schools. The first step is to concatenate 10 different data sets. I want to keep the source of the data, that is, which data set it came from, so if there are issues with these data, outliers, etc. I can more easily pinpoint where it occurred.<\/p>\n\n\n\n<p>I used the IN= option for each data set when I read them in and then some IF statements to assign a source. <\/p>\n\n\n\n<p>DATA mydata.all_users18 ;<br\/>\u00a0 \u00a0 SET\u00a0 sl_pre_users18 (in=slp ) <br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 aztech_pre_clean (in=azp ) <br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 AZ_maya_students18 (in=azms) <br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 fl_pretest_new18 (in=flpn)<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 fl_pretest_old18 (in=flpo)<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ft_users18(in=ft)<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 mydata.fl_students18 (in=fls )<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 mc_bilingual_students18 (in=mcb) <br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 mc_users18 (in=mc)<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 mydata.sl_students18 (in=sls)<br\/>;<\/p>\n\n\n\n<p>After I run the data step, I see that 425 observations do not have a value for &#8220;source&#8221;. How would you spot the error? <\/p>\n\n\n\n<p>Of course, there is more than one way, but I thought the simplest thing was to search in the SAS log and see which of the data sets had exactly 425 observations. Yep. There it is. Took me 2 seconds to find. <br\/><\/p>\n\n\n\n<p>147 PROC IMPORT DATAFILE=REFFILE<br\/> 148 DBMS=XLSX <br\/>149 OUT=WORK.MC_bilinguaL_students18 replace; <br\/>150 GETNAMES=YES; <br\/><\/p>\n\n\n\n<p>NOTE: The import data set has 425 observations and 2 variables.<\/p>\n\n\n\n<p>So, I looked at the code again and sure enough, I had misspelled &#8220;source&#8221;<\/p>\n\n\n\n<p>IF\u00a0 slp THEN source = &#8220;Spirit Pre&#8221; ;<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0 else if azp then source = &#8220;Az Pre&#8221; ;<br\/>\u00a0\u00a0\u00a0\u00a0 else if fls then source = &#8220;Fish Studn&#8221;;<br\/>\u00a0\u00a0\u00a0\u00a0 else if mcb then sourc = &#8220;M.Camp.Bil&#8221; ;<\/p>\n\n\n\n<p>You might think I could have just read through the code, and you are right, but there were a lot of lines of code. In this case, I could immediately identify that it was something to do with that specific data set and reduce the code I needed to look at significantly. I just started with the last place that data set was referenced to work backward. Fortunately for me, it was in the very last place I called it. <\/p>\n\n\n\n<p>The fact is, you will probably spend as much time debugging code as you do writing it. The log and logic are your friends. Also, no matter how long you have been programming you still make typos.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"900\" height=\"506\" src=\"http:\/\/www.thejuliagroup.com\/blog\/wp-content\/uploads\/2018\/11\/7GGFishLake.jpg\" alt=\"\" class=\"wp-image-5662\" srcset=\"https:\/\/www.thejuliagroup.com\/blog\/wp-content\/uploads\/2018\/11\/7GGFishLake.jpg 900w, https:\/\/www.thejuliagroup.com\/blog\/wp-content\/uploads\/2018\/11\/7GGFishLake-300x169.jpg 300w, https:\/\/www.thejuliagroup.com\/blog\/wp-content\/uploads\/2018\/11\/7GGFishLake-768x432.jpg 768w\" sizes=\"auto, (max-width: 900px) 100vw, 900px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><a href=\"http:\/\/www.7generationgames.com\/fish-lake\/\">Want to play one of the games from this study? Have a computer? Go ahead, maturity is over-rated.<\/a><\/h3>\n\n\n\n<p><br\/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I was reminded today how useful a SAS log can be, even when it doesn&#8217;t give you any errors. I&#8217;m analyzing data from a study on educational technology in rural schools. The first step is to concatenate 10 different data sets. I want to keep the source of the data, that is, which data set&#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],"tags":[],"class_list":["post-5661","post","type-post","status-publish","format-standard","hentry","category-software"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/posts\/5661","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=5661"}],"version-history":[{"count":1,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/posts\/5661\/revisions"}],"predecessor-version":[{"id":5663,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/posts\/5661\/revisions\/5663"}],"wp:attachment":[{"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/media?parent=5661"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/categories?post=5661"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/tags?post=5661"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}