{"id":5873,"date":"2023-07-16T13:13:05","date_gmt":"2023-07-16T18:13:05","guid":{"rendered":"https:\/\/www.thejuliagroup.com\/blog\/?p=5873"},"modified":"2023-07-16T22:34:27","modified_gmt":"2023-07-17T03:34:27","slug":"why-wont-sas-see-this-character-variable-is-equal","status":"publish","type":"post","link":"https:\/\/www.thejuliagroup.com\/blog\/why-wont-sas-see-this-character-variable-is-equal\/","title":{"rendered":"Why won&#8217;t SAS see this character variable is equal?"},"content":{"rendered":"\n<p>Playing around today with possible activities for my Biostatistics course and used this simulated random sample of race by antigen type.  Here is a random trivia question for you that took me about 10 minutes to figure out.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">By the way, ChatGPT did not help<\/h2>\n\n\n\n<p>I&#8217;m interested in how my students could use ChatGPT or other AI, so I often paste questions into ChatGPT or Google Bard to see how the answers compare to reality. ChatGPT said this code should return observations for the second analysis, but it did not.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The second PROC FREQ said &#8220;no observations&#8221;.  Why?<\/h2>\n\n\n\n<p>The first chi-square showed, as expected, not enough observations per cell. I decided to try to get a 2x 2 contingency table and a Fisher&#8217;s chi-square, but first I was just going to do a chi-square for two racial groups.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>data blood ;\n\tinput race $  num  antigen $ ;\n\tdatalines;\n\twhite 15 a_anti\n\twhite 6 b_anti \n\twhite  0 ab_anti \n\twhite  29 no_antigen\n\tafrican_am 7 a_anti\n\tafrican_am 4 b_anti \n\tafrican_am  0 ab_anti \n\tafrican_am  9 no_antigen\n\tasian_am 7 a_anti\n\tasian_am  5 b_anti \n\tasian_am   1 ab_anti \n\tasian_am   7 no_antigen\n\t;\n\t\n   Title \"Data from https:\/\/sciencecourseware.org\/biol300\/bloodgroups.html\" ;\nproc freq data=blood ;\n  tables race*antigen \/ chisq;\n  weight num ;\n  run;\nproc freq data=blood ;\n  tables race*antigen \/ chisq;\n  where race in (\"white\",\"asian_am\") ;\n  weight num ;\n  run;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">How I figured it out<\/h2>\n\n\n\n<p>First, I looked at the output for the initial chi-square and saw race was listed as &#8220;white&#8221; and &#8220;asian_a&#8221;. So, I thought perhaps it was truncating the value of race when it was read in to 8 characters &#8211; but that doesn&#8217;t explain why &#8220;white&#8221; didn&#8217;t match. Anyway, I tried it again with &#8220;white&#8221; and &#8220;asian_a&#8221; as the two values and still nothing.<\/p>\n\n\n\n<p>I thought perhaps there were trailing blanks, I tried using the trim function to remove trailing blanks. Still, no observations.<\/p>\n\n\n\n<p>I did this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>DATA test2;\n   SET blood ;\n   SUBSTR(race,1,3) ;\nPROC PRINT DATA = test2 ;\n<\/code><\/pre>\n\n\n\n<p>And that&#8217;s when I spotted it &#8211; the first three characters were &#8221; wh&#8221; and &#8221; as&#8221;.  There was a LEADING blank! <\/p>\n\n\n\n<p>There is a function for deleting all blanks as well but I actually just went and deleted the 12 spaces in the 12 lines and it worked. <\/p>\n\n\n\n<p>How did those leading blanks get in there in the first place? I don&#8217;t know. I might have just typed a space without thinking or copied the labels from a table. <\/p>\n\n\n\n<p><em>It&#8217;s a little thing, but all told, I spent 10 minutes trying to figure this out, so I thought I&#8217;d post the answer here.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>When I selected observations where the character variable was equal to a certain value, SAS returned 0 observations &#8211; but I knew there should be a match!<\/p>\n","protected":false},"author":2,"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":[30,9],"tags":[],"class_list":["post-5873","post","type-post","status-publish","format-standard","hentry","category-programming-tips","category-software"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/posts\/5873","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\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/comments?post=5873"}],"version-history":[{"count":2,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/posts\/5873\/revisions"}],"predecessor-version":[{"id":5875,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/posts\/5873\/revisions\/5875"}],"wp:attachment":[{"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/media?parent=5873"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/categories?post=5873"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/tags?post=5873"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}