{"id":5628,"date":"2018-08-12T21:22:08","date_gmt":"2018-08-13T02:22:08","guid":{"rendered":"http:\/\/www.thejuliagroup.com\/blog\/?p=5628"},"modified":"2018-08-12T21:28:10","modified_gmt":"2018-08-13T02:28:10","slug":"use-title-and-label-statements-to-document-sas-code","status":"publish","type":"post","link":"https:\/\/www.thejuliagroup.com\/blog\/use-title-and-label-statements-to-document-sas-code\/","title":{"rendered":"Use Title and Label Statements to Document SAS Code"},"content":{"rendered":"<p>&nbsp;<\/p>\n<blockquote><p>&#8220;I don&#8217;t document my code because if you really understood the language, it should be obvious.&#8221;<\/p><\/blockquote>\n<p>&#8211; Bob<\/p>\n<p>Bob is an arrogant little prick.<\/p>\n<p>Here are just a few reasons to document your code.<\/p>\n<ol>\n<li>Other people may need to modify it because, despite your assumed brilliance, there may be other people in the universe capable of maintaining your code when you get a promotion, take another job or get your sorry ass fired.<\/li>\n<li>Six months from now, you may need to look at this code again. After 11 other projects have intervened, you&#8217;ll be trying to figure out what the hell the prev_grant_yrs variable was supposed to measure. Every time I add comments to a project, I say to myself, &#8220;Future me will thank me for this.&#8221;<\/li>\n<li>If you use Title and Label statements, there will be additional clarity not just for you as a programmer but also for the users.<\/li>\n<\/ol>\n<h3>Here is an example<\/h3>\n<p>This comes from a longitudinal analysis of a vocational rehabilitation project. There are only two comment statements in this snippet, however, there is a LABEL statement which explains that the prev_grant_yrs variable is the number of years a consumer was served under the previous grant. There was a significant change in operations in the current grant cycle, but when this five-year cycle started there were a number of people already on the caseload who had been determined eligible under the previous administration.<br \/>\n<code><br \/>\ndata by_year ;<br \/>\nset mydata.vr2018 ;<\/code><\/p>\n<p><code>** USES YEAR FUNCTION TO GET THE YEAR OF INDIVIDUAL PLAN OF EMPLOYMENT ;<\/code><\/p>\n<p><code>*** AND OF APPLICATION TO THE PROGRAM ;<\/code><\/p>\n<p><code><br \/>\nipe_year = year(ipe_date) ;<br \/>\napp_year = year(app_date);<br \/>\n<\/code><\/p>\n<p><code>if ipe_year ne . and ipe_year &lt; 2008 then prev_grant_yrs = \"5+\" ;<br \/>\nelse if ipe_year &lt; 2012 then prev_grant_yrs = \"2-4\" ; <\/code><\/p>\n<p><code>\u00a0 else if ipe_year &gt; 2011 then prev_grant_yrs = \"0-1\";<\/code><\/p>\n<p><code>LABEL prev_grant_yrs = \"Years Under Previous Grant\"<br \/>\nipe_year = \"Year IPE written\"<\/code><\/p>\n<p><code> app_year = \"Year applied\" <\/code><\/p>\n<p><code> <\/code><code>;<\/code><\/p>\n<p>The first procedure, I simply wanted to get a closer look at the people who had been getting services for more than five years under the previous grants. It&#8217;s important to add that second title line so readers know this isn&#8217;t ALL long-term consumers but those who had been long-term users coming into the current grant cycle.<\/p>\n<p><code>TITLE \"Check long-term consumers\";<\/code><\/p>\n<p><code>TITLE2 \"Getting services 5+ under the previous grant\" ;<br \/>\nproc print data= by_year ;<br \/>\nwhere prev_grant_yrs = \"+5\";<br \/>\nid username ;<br \/>\nvar ipe_date app_year prev_grant_yrs ;<br \/>\nformat ipe_date mmddyy8. ;<br \/>\n<\/code><\/p>\n<p>The second procedure, I wanted to see how consumers served in the current year were doing. Why do I have grantyear as a variable in the VAR statement when it is clear from the WHERE statement that only people from 2018 will be included?\u00a0 Because the person who gets the output won&#8217;t see that WHERE statement. Just having &#8220;current year&#8221; in the title is not enough because next January someone looking at this might think it was for 2019.\u00a0 I could have included 2018 in the title, but including it as a variable on the output both acts as a validity check for me and lets the user, my customer, know that the data are correct.<\/p>\n<p><code>TITLE \"Current year consumers\" ;<br \/>\nproc print data=by_year ;<br \/>\nwhere grantyear = 2018 ;<br \/>\nid username ;<br \/>\nvar grantyear status status_type ipe_year;<br \/>\nformat ipe_year mmddyy8. ;<br \/>\n<\/code><\/p>\n<p>A few of the individuals served by this project did not have an Individual Plan of Employment. I wanted to see if the people missing an IPE just hadn&#8217;t had time to complete it yet or if they never came back and did it. An IPE is the first step in getting project services, so, if they had a missing date for a year or more than they had just dropped out. Again, the second title line tells the users what I&#8217;m trying to do here.<\/p>\n<p><code>TITLE \"IPE YEAR by Application Year\";<br \/>\nTITLE2 \"Note: Missing IPE consumers had ample time to complete IPE\";<br \/>\nproc freq data=by_year ;<br \/>\ntables ipe_year*app_year\/missing ;<\/code><\/p>\n<p>So, you get the idea. Elegant code is nice, correct code is essential.<\/p>\n<p>You know what is essential?<\/p>\n<p>A young person once asked me,<\/p>\n<blockquote>\n<h3>&#8220;No offense, but why are your services so much in demand? It&#8217;s not as if there aren&#8217;t a lot of people who can do what you do.&#8221;<\/h3>\n<\/blockquote>\n<p>Okay, first tip, young people, when you find yourself saying, &#8220;no offense&#8221; you should probably just stop talking and then you definitely won&#8217;t offend anyone. Actually, I was pretty amused. It&#8217;s true that lots of people can do frequency distributions, if-then-else statements and cross-tabulations (although, in my defense, that&#8217;s not ALL I did on this project).<\/p>\n<p>One essential skill is make your analyses easily understood by your co-workers and customers.<\/p>\n<p>As a wise person once said,<\/p>\n<blockquote><p>&#8220;Mystery novels should be figured out. Code should be read.&#8221;<\/p><\/blockquote>\n<hr \/>\n<h2>Wonder what else I&#8217;m writing these days?<\/h2>\n<h3><a href=\"http:\/\/www.7generationgames.com\/a-different-kind-of-textbook\/\">You can get A Different Kind of Textbook, our family group text, for $2.99 as an ebook.<\/a>\u00a0 We definitely are a different kind of family.<\/h3>\n<p><a href=\"http:\/\/www.thejuliagroup.com\/blog\/wp-content\/uploads\/2018\/08\/7-Generation-Games-Text-Book_Page_06.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-5636\" src=\"http:\/\/www.thejuliagroup.com\/blog\/wp-content\/uploads\/2018\/08\/7-Generation-Games-Text-Book_Page_06-561x1024.jpg\" alt=\"Contacts : bios of family members\" width=\"561\" height=\"1024\" srcset=\"https:\/\/www.thejuliagroup.com\/blog\/wp-content\/uploads\/2018\/08\/7-Generation-Games-Text-Book_Page_06-561x1024.jpg 561w, https:\/\/www.thejuliagroup.com\/blog\/wp-content\/uploads\/2018\/08\/7-Generation-Games-Text-Book_Page_06-164x300.jpg 164w, https:\/\/www.thejuliagroup.com\/blog\/wp-content\/uploads\/2018\/08\/7-Generation-Games-Text-Book_Page_06-768x1401.jpg 768w, https:\/\/www.thejuliagroup.com\/blog\/wp-content\/uploads\/2018\/08\/7-Generation-Games-Text-Book_Page_06.jpg 1118w\" sizes=\"auto, (max-width: 561px) 100vw, 561px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; &#8220;I don&#8217;t document my code because if you really understood the language, it should be obvious.&#8221; &#8211; Bob Bob is an arrogant little prick. Here are just a few reasons to document your code. Other people may need to modify it because, despite your assumed brilliance, there may be other people in the universe&#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-5628","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\/5628","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=5628"}],"version-history":[{"count":6,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/posts\/5628\/revisions"}],"predecessor-version":[{"id":5637,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/posts\/5628\/revisions\/5637"}],"wp:attachment":[{"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/media?parent=5628"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/categories?post=5628"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/tags?post=5628"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}