{"id":5617,"date":"2018-07-24T09:27:53","date_gmt":"2018-07-24T14:27:53","guid":{"rendered":"http:\/\/www.thejuliagroup.com\/blog\/?p=5617"},"modified":"2018-07-24T09:27:53","modified_gmt":"2018-07-24T14:27:53","slug":"sas-tip-of-the-day-the-_character_-array-and-fixing-all-character-variables","status":"publish","type":"post","link":"https:\/\/www.thejuliagroup.com\/blog\/sas-tip-of-the-day-the-_character_-array-and-fixing-all-character-variables\/","title":{"rendered":"SAS Tip of the Day: The _character_ array and fixing all character variables"},"content":{"rendered":"<p>Contrary to appearances, this is not an abandoned blog. I&#8217;ve been super-busy with <a href=\"http:\/\/www.7generationgames.com\/products\/\">7 Generation Games, where we released two new games <\/a>and a customized app for a client this month! At the same time,<a href=\"http:\/\/strongmindstudios.com\/blog\/\"> I&#8217;m in Santiago, Chile piloting games for our Spanish language brand, Strong Mind Studios, you can read some of my blog in Spanish here<\/a>.<\/p>\n<figure id=\"attachment_5618\" aria-describedby=\"caption-attachment-5618\" style=\"width: 225px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.thejuliagroup.com\/blog\/wp-content\/uploads\/2018\/07\/IMG_0862-e1532440342863.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-5618 size-medium\" src=\"http:\/\/www.thejuliagroup.com\/blog\/wp-content\/uploads\/2018\/07\/IMG_0862-e1532440342863-225x300.jpg\" alt=\"Santa Lucia\" width=\"225\" height=\"300\" srcset=\"https:\/\/www.thejuliagroup.com\/blog\/wp-content\/uploads\/2018\/07\/IMG_0862-e1532440342863-225x300.jpg 225w, https:\/\/www.thejuliagroup.com\/blog\/wp-content\/uploads\/2018\/07\/IMG_0862-e1532440342863.jpg 338w\" sizes=\"auto, (max-width: 225px) 100vw, 225px\" \/><\/a><figcaption id=\"caption-attachment-5618\" class=\"wp-caption-text\">Santa Lucia, next door<\/figcaption><\/figure>\n<p>I decided to get back to blogging with a SAS tip of the day. Today&#8217;s tip is about the _character_ array.<\/p>\n<h3>If you didn&#8217;t know, now you know: All character variables are in the _character_ array<\/h3>\n<p>Often, I want to do something to every character variable in a data set, for example, set all of the values to upper case, so &#8220;diabetes&#8221;, &#8220;Diabetes&#8221; and &#8220;DIABETES&#8221; are not counted as three, different disabilities. Because I hate to expend unnecessary effort, I don&#8217;t want to list the names of every character variable and I don&#8217;t want to count how many there are because I&#8217;ll probably count wrong and then end up with errors.<\/p>\n<p>Here is an example using the _character_ array.<\/p>\n<p><code>data fixdata ;<br \/>\nset fix1;<br \/>\narray fixchars {*} _character_ ;<br \/>\n** Change all character values to upper case ;<br \/>\ndo i = 1 to dim(fixchars);<br \/>\nfixchars{i} = upcase(fixchars{i}) ;<br \/>\nend ;<\/code><\/p>\n<p>Just use an ARRAY statement, give your array a name and in the {} instead of the number of elements put a *\u00a0 which SAS interprets as &#8220;the number of variables in the array are however many character variables there happen to be.<\/p>\n<p>You might think you&#8217;d have to use the $ to specify that the _character_ array consists of character variables, but that&#8217;s kind of overkill and you actually don&#8217;t. It will work either way.<\/p>\n<p>In my DO statement, I use the DIM function which will return the dimension of the array. That is, DO I = 1 to DIM(array_name) will do the statements from the first variable to however many happen to be in the array.<\/p>\n<p>As you might guess, the UPCASE function returns the value in all upper case.<\/p>\n<hr \/>\n<p><a href=\"http:\/\/www.7generationgames.com\/making-camp-premium\/\">Have a kid? Like kids? Feel like a kid yourself? Check out our new game, Making Camp Premium, because maturity is over-rated.<\/a><\/p>\n<p><a href=\"http:\/\/www.thejuliagroup.com\/blog\/wp-content\/uploads\/2018\/07\/making_camp_premium3.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-5619\" src=\"http:\/\/www.thejuliagroup.com\/blog\/wp-content\/uploads\/2018\/07\/making_camp_premium3-300x200.jpg\" alt=\"\" width=\"300\" height=\"200\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Contrary to appearances, this is not an abandoned blog. I&#8217;ve been super-busy with 7 Generation Games, where we released two new games and a customized app for a client this month! At the same time, I&#8217;m in Santiago, Chile piloting games for our Spanish language brand, Strong Mind Studios, you can read some of my&#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-5617","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\/5617","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=5617"}],"version-history":[{"count":1,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/posts\/5617\/revisions"}],"predecessor-version":[{"id":5621,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/posts\/5617\/revisions\/5621"}],"wp:attachment":[{"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/media?parent=5617"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/categories?post=5617"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/tags?post=5617"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}