{"id":4970,"date":"2016-02-09T02:19:16","date_gmt":"2016-02-09T07:19:16","guid":{"rendered":"http:\/\/www.thejuliagroup.com\/blog\/?p=4970"},"modified":"2016-02-09T02:19:16","modified_gmt":"2016-02-09T07:19:16","slug":"watch-me-work-finishing-the-test-scoring-with-more-sas-character-functions","status":"publish","type":"post","link":"https:\/\/www.thejuliagroup.com\/blog\/watch-me-work-finishing-the-test-scoring-with-more-sas-character-functions\/","title":{"rendered":"Watch me work: Finishing the test scoring with more SAS character functions"},"content":{"rendered":"<p>Recall that <a href=\"http:\/\/www.thejuliagroup.com\/blog\/?p=4964\">in the last post we were using SAS functions to score a test <\/a>that had been completed by middle school and upper elementary students. Since we wanted to make it as easy as possible for students to enter their answers, we accepted just about any format.<\/p>\n<p>Picking up where we left off &#8230;<\/p>\n<p><strong>SUBSTR FUNCTION &#8211; READING ONLY PART OF AN ANSWER<\/strong><\/p>\n<p>In one question, the correct answer is 1\/8 . Students entered 1\/8, 1\/8 cup, 1\/8 cup of beans, and so on.\u00a0 To score these, we use the substr function to read the first 3 characters and score the problem correct if those are &#8220;1\/8&#8221;<\/p>\n<p>If substr(q22,1,3) = &#8220;1\/8&#8221; then q22 = 1 ;<\/p>\n<p>else q22 = 0 ;<\/p>\n<p><strong>MISSING FUNCTION &#8211; TO CHECK FOR MISSING DATA<\/strong><\/p>\n<p>For q27, students clicked on which of the equations\u00a0are correct. If they clicked the correct equation, the variable was set\u00a0 to 1.<\/p>\n<p>When they didn&#8217;t click on anything, it was missing. I wanted that to be changed to a zero, so I used the missing function, like this:<\/p>\n<p>if missing(q27) then q27 = 0 ;<\/p>\n<p><strong>ARRAY, DO-LOOP and INPUT FUNCTION<\/strong><\/p>\n<p>Now, SAS is not the newest kid on the block<\/p>\n<p>and I can relate, because neither am I, not even if I&#8217;m on a relatively old block<\/p>\n<p><a href=\"http:\/\/www.thejuliagroup.com\/blog\/wp-content\/uploads\/2016\/02\/old.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4975\" src=\"http:\/\/www.thejuliagroup.com\/blog\/wp-content\/uploads\/2016\/02\/old.jpg\" alt=\"Old and middle-aged people\" width=\"416\" height=\"293\" srcset=\"https:\/\/www.thejuliagroup.com\/blog\/wp-content\/uploads\/2016\/02\/old.jpg 416w, https:\/\/www.thejuliagroup.com\/blog\/wp-content\/uploads\/2016\/02\/old-300x211.jpg 300w\" sizes=\"auto, (max-width: 416px) 100vw, 416px\" \/><\/a><\/p>\n<p>The problem with being an older language is that\u00a0 you have static types and you cannot have mixed arrays. What does that mean? It means that if you have defined q1 as a character variable because it might have a $ in it then by God it is going to stay a character variable and you can&#8217;t be doing any funny stuff like finding the mean and standard deviation of it. Also, if you are going to have an array, everything in it better be either all character variables or all numeric variables.<\/p>\n<p>Well, fine, then, here is how I change all those now scored questions to numeric. First, I created a new numeric array of 32 items. You can tell it is numeric because there is no $.<\/p>\n<p>Second, I used a DO loop and the INPUT function. The input function will read in a variable and and read it out in a different format, in this case, a numeric variable with a length of 8 and 0 decimal places.<\/p>\n<p>I dropped the index variables j and i , which I mentioned in a previous post.<\/p>\n<p>Now that I have my variables all nicely numeric, I can use the SUM function and add up all of the scored items into a total score.<\/p>\n<p>&nbsp;<\/p>\n<p>array items {32} item1 &#8211; item32 ;<\/p>\n<p>do j = 1 to 32 ;<br \/>\nitems{j} = input(qs{j},8.0);<br \/>\nend;<br \/>\ndrop i j ;<br \/>\ntotal = sum(of item1-item32);<\/p>\n<p>&nbsp;<\/p>\n<p>Now that I have my data, the fun stuff begins, but that&#8217;s for another post because I need to get back to making games.<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"http:\/\/www.7generationgames.com\/buy\/\">This is my day job. Check it out. Buy a game. Maturity is over-rated!<\/a><\/p>\n<p><a href=\"http:\/\/www.7generationgames.com\/buy\/\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4192\" src=\"http:\/\/www.thejuliagroup.com\/blog\/wp-content\/uploads\/2014\/07\/villageburned.png\" alt=\"burning village\" width=\"450\" height=\"254\" srcset=\"https:\/\/www.thejuliagroup.com\/blog\/wp-content\/uploads\/2014\/07\/villageburned.png 450w, https:\/\/www.thejuliagroup.com\/blog\/wp-content\/uploads\/2014\/07\/villageburned-300x169.png 300w\" sizes=\"auto, (max-width: 450px) 100vw, 450px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/www.7generationgames.com\/buy\/\">Or donate a game to a school for good karma.<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recall that in the last post we were using SAS functions to score a test that had been completed by middle school and upper elementary students. Since we wanted to make it as easy as possible for students to enter their answers, we accepted just about any format. Picking up where we left off &#8230;&#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-4970","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\/4970","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=4970"}],"version-history":[{"count":4,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/posts\/4970\/revisions"}],"predecessor-version":[{"id":4976,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/posts\/4970\/revisions\/4976"}],"wp:attachment":[{"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/media?parent=4970"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/categories?post=4970"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/tags?post=4970"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}