{"id":2239,"date":"2012-03-23T02:59:29","date_gmt":"2012-03-23T07:59:29","guid":{"rendered":"http:\/\/www.thejuliagroup.com\/blog\/?p=2239"},"modified":"2012-03-23T03:00:46","modified_gmt":"2012-03-23T08:00:46","slug":"it-beats-working-backward-from-the-semi-colon","status":"publish","type":"post","link":"https:\/\/www.thejuliagroup.com\/blog\/it-beats-working-backward-from-the-semi-colon\/","title":{"rendered":"It Beats Working Backward from the Semi-Colon"},"content":{"rendered":"<p>My niece, Samantha, should be far more trusting at her tender age. She was skeptical &#8211; skeptical, I say! &#8211; that I once worked at a job where I got so bored that I started coding my SAS statements\u00a0backwards, typing a semi-colon first and then working backwards, say to PROC .<\/p>\n<p>Non-naive nieces aside, it is nonetheless true.<\/p>\n<p>I left that job before I had progressed to starting at the end of the program and working backward up to LIBNAME.<\/p>\n<p>Lately, I have had a lot of similar problems where I needed to recode data. All of these involved rectangular data sets &#8211; that is, hundreds of variables over a few hundred people &#8211; so speed and efficiency of processing were negligible concerns.<\/p>\n<p>A few days ago, I gave a solution when you have, for some bizarro reason, <a href=\"http:\/\/www.thejuliagroup.com\/blog\/?p=2217\">questions on a one to five scale coded into five different variables<\/a>. Before that, I had a similar problem <a href=\"http:\/\/www.thejuliagroup.com\/blog\/?p=2206\">when true \/ false questions were coded into two variables<\/a>.<\/p>\n<p>Later in the week, I ran into essentially the same problems but I was bored with doing it the same way. \u00a0In this case, there were about a zillion questions where people were to check any that applied.<\/p>\n<p><strong>Check all of the things you have in your pocket right now<\/strong><\/p>\n<p>__ a penny<a href=\"http:\/\/www.thejuliagroup.com\/blog\/wp-content\/uploads\/2012\/03\/chicken.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-thumbnail wp-image-2240 alignleft\" title=\"chicken\" src=\"http:\/\/www.thejuliagroup.com\/blog\/wp-content\/uploads\/2012\/03\/chicken-150x150.jpg\" alt=\"A chicken\" width=\"150\" height=\"150\" \/><\/a><\/p>\n<p>__ keys<\/p>\n<p>__ USB drive<\/p>\n<p>__ lint<\/p>\n<p>__ guinea pig poop<\/p>\n<p>__ a chicken<\/p>\n<p>__ Julia De Mars&#8217; cell phone<\/p>\n<p>These are scored a 1 if checked and missing if not. It we do the mean, we would get 1 for every item, because everyone who did not check an item had a missing value. Having a 0 if they did not check it would be better. For one thing, when we do a PROC MEANS it will tell us what percentage of people selected this item. (If you have Julia&#8217;s cell phone, give it back.)<\/p>\n<p>This \u00a0time I used a PROC FORMAT, like this:<\/p>\n<p><code>PROC FORMAT ;<br \/>\nVALUE \u00a0yn<br \/>\n1 = 1<br \/>\n. = 0 ;<\/code><\/p>\n<p><code>DATA scoredfile ;<\/code><br \/>\n<code>SET oldfile ;<br \/>\nARRAY yn{*} q0041_00 -- \u00a0 Q0051_04 \u00a0;<br \/>\nDO \u00a0x = 1 to DIM(yn) ;<br \/>\nyn{x} = PUT(yn{x},yn.) ;<br \/>\nEND \u00a0; <\/code><\/p>\n<p>The PUT function puts the formatted value of the element in the array yn back into that variable. Generally I am a bit gunshy about recoding variables into themselves but notice that I re-named the file so it is pretty clear it has been scored already.<\/p>\n<p>Shortly after this problem, I had a test with a gazillion questions and each one, in the manner of tests, was scored right or wrong. \u00a0However, it turns out that the answer to every question was not C , contrary to what you put on your SATs (and now you know why you did not get into UCLA ). The example below only shows three, but actually there were six choices, which made this a little more worth doing.<\/p>\n<p>So, I created a macro. I used the same index variable, i, for each array. One less thing to delete at the end of the job. There are only two parameters and they are both required, the array name and the number.<\/p>\n<p>For each array, say, all of the items with the correct answer 1 (how A was stored in our file), it will score the item 1 if the answer 1 was given and 0 otherwise. This is a test, so whether you got it wrong or you skipped it you get a zero either way. If you knew the answer, you should have \u00a0answered it.<\/p>\n<p>I can call this macro six times, just giving the name of the array and the correct answer.<\/p>\n<p>%macro sa(aname,num) ;<br \/>\ni = 1;<br \/>\ndo i = 1 to dim(&amp;aname) ;<br \/>\nif &amp;aname{i} = &amp;num then &amp;aname{i} = 1 ;<br \/>\nelse\u00a0&amp;aname{i} = 0 ;<\/p>\n<p>end ;<br \/>\n%mend sa ;<\/p>\n<p><code>DATA scoredfile ;<\/code><br \/>\n<code>SET oldfile ;<br \/>\narray a1{*} q0004 q0007 q0008 q0009 q0014 q0016 ;<br \/>\narray a2{*} q0005 q0006 q0013 ;<br \/>\narray a3{*} q0011 q0012 q0015 q0018 q0020 q0022 q0024 ;<br \/>\n%sa(a1,1) ;<br \/>\n%sa(a2,2) ;<br \/>\n%sa(a3,3) ;<br \/>\n<\/code><br \/>\nSo, there you have it, two more ways to solve the same problem. Thank God all of the data are read in and we can go on to analyzing it, though, because much more of this and I would have started writing backwards from the semi-colon.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>My niece, Samantha, should be far more trusting at her tender age. She was skeptical &#8211; skeptical, I say! &#8211; that I once worked at a job where I got so bored that I started coding my SAS statements\u00a0backwards, typing a semi-colon first and then working backwards, say to PROC . Non-naive nieces aside, it&#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-2239","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\/2239","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=2239"}],"version-history":[{"count":3,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/posts\/2239\/revisions"}],"predecessor-version":[{"id":2243,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/posts\/2239\/revisions\/2243"}],"wp:attachment":[{"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/media?parent=2239"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/categories?post=2239"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/tags?post=2239"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}