<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Supposed Array Character Missassignment in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Supposed-Array-Character-Missassignment/m-p/509629#M137020</link>
    <description>Which likely means it's either a source data issue or something we're not seeing (previous code) that's causing the issues. &lt;BR /&gt;&lt;BR /&gt;FYI - you can speed this up by using temporary arrays and loading them from a data set if you have it or using a format which would be significantly faster.</description>
    <pubDate>Thu, 01 Nov 2018 17:51:29 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2018-11-01T17:51:29Z</dc:date>
    <item>
      <title>Supposed Array Character Missassignment</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Supposed-Array-Character-Missassignment/m-p/509616#M137011</link>
      <description>&lt;P&gt;Hi folks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've got a large dataset of character values for which I want to create a category variable. What I decided would be the easiest approach would be to create arrays for each valid category and then create the variable based on if the value is found in a given array. A simplified example is shown below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data categorize;
   set originaldata;
   category = "none";

   array categoryone (50) $ ("a", "b", "c", "d",...);
   array categorytwo (200) $ ("aaa", "aab", "aac",...);

   if readvariable in categoryone then category = "1";
      else if readvariable in categorytwo then category = "2";
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I'm noticing when checking proc freq is that my category variable is "None" for the whole dataset. In trying to figure out why I decided to check my created arrays.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Upon checking the arrays I saw that the values were assigned incorrectly such as categoryone1 given a value of "s" instead of the expected value of "a" and that categoryone2-categoryone6 was also given a value of "s". I've tried looking around for what I'm doing wrong in my array assignment and have tried things such as removing the ","s, but to no avail. I realize that my issue is likely multifaceted, but I can't find documentation that states where or how. Help me SAS Community boards. You're my only hope.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Nov 2018 17:17:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Supposed-Array-Character-Missassignment/m-p/509616#M137011</guid>
      <dc:creator>jdchang</dc:creator>
      <dc:date>2018-11-01T17:17:11Z</dc:date>
    </item>
    <item>
      <title>Re: Supposed Array Character Missassignment</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Supposed-Array-Character-Missassignment/m-p/509618#M137012</link>
      <description>&lt;P&gt;Would you be able to provide a representative sample of your data and your required output?&lt;/P&gt;</description>
      <pubDate>Thu, 01 Nov 2018 17:26:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Supposed-Array-Character-Missassignment/m-p/509618#M137012</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-11-01T17:26:11Z</dc:date>
    </item>
    <item>
      <title>Re: Supposed Array Character Missassignment</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Supposed-Array-Character-Missassignment/m-p/509622#M137014</link>
      <description>&lt;P&gt;Sure thing. The actual data looks close to this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data sample1; 
	set sample;

	array secgen (192) $ 	("50580073001" "50580073005" "50580073006" "50580072105" "50580078201" "50580078212" "50580078224" ...)
	array firgen (1318) $ firgen1-firgen1318 ("50580037001", "76413033224", "66715970602", "66715970603", "61786086636",	"50580022650" ...)
        array cromo (20) $ cromo1-cromo20 ("17478029111", "59779007513", "70556010260", "50090312500", "69784020096" ...)

	if ndcnum in secgen then drug = "secgen";
		else if ndcnum in firgen then drug = "firgen";
		else if ndcnum in cromo then drug = "cromo";

run;

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As I have it now I tried removing commas and not specifically naming array variables in the first array, but am still seeing the same issues as prior. The ndcnum variable is also a character variable of length 11 formatted to match the other values listed in the created arrays. There are several more categories as well, but they all have the same initialization and utilization as demonstrated above. Seriously scratching my head as to why I'm seeing the issues I'm seeing.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Nov 2018 17:38:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Supposed-Array-Character-Missassignment/m-p/509622#M137014</guid>
      <dc:creator>jdchang</dc:creator>
      <dc:date>2018-11-01T17:38:32Z</dc:date>
    </item>
    <item>
      <title>Re: Supposed Array Character Missassignment</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Supposed-Array-Character-Missassignment/m-p/509624#M137016</link>
      <description>&lt;P&gt;You are giving the code rather than the data. A sample(mock) data of what you have and what you want in your output would help to copy paste to our SAS environment and test your logic(code)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;what does this&lt;STRONG&gt; set sample&lt;/STRONG&gt; contain?&lt;/P&gt;
&lt;P&gt;ndcnum var should be in set sample right?&lt;/P&gt;</description>
      <pubDate>Thu, 01 Nov 2018 17:42:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Supposed-Array-Character-Missassignment/m-p/509624#M137016</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-11-01T17:42:31Z</dc:date>
    </item>
    <item>
      <title>Re: Supposed Array Character Missassignment</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Supposed-Array-Character-Missassignment/m-p/509626#M137018</link>
      <description>It would help if you could generate a full sample and clearly show the problematic output. I can't quite seem to understand what the issue is yet.</description>
      <pubDate>Thu, 01 Nov 2018 17:44:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Supposed-Array-Character-Missassignment/m-p/509626#M137018</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-11-01T17:44:26Z</dc:date>
    </item>
    <item>
      <title>Re: Supposed Array Character Missassignment</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Supposed-Array-Character-Missassignment/m-p/509628#M137019</link>
      <description>&lt;P&gt;Your sample code works.&amp;nbsp; You may not have all of the array values set in you arrays.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data originaldata;
input readvariable $;
cards;
a
b
c
d 
f
g
aa1
aaa
aab
aac
aad
;


data categorize;
   set originaldata;
   category = "none";

   array categoryone (50) $ ("a", "b", "c", "d");
   array categorytwo (200) $ ("aaa", "aab", "aac");

   if readvariable in categoryone then category = "1";
   else if readvariable in categorytwo then category = "2";
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;you have a lot of ….. that were in the way which I removed. &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Nov 2018 17:49:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Supposed-Array-Character-Missassignment/m-p/509628#M137019</guid>
      <dc:creator>VDD</dc:creator>
      <dc:date>2018-11-01T17:49:50Z</dc:date>
    </item>
    <item>
      <title>Re: Supposed Array Character Missassignment</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Supposed-Array-Character-Missassignment/m-p/509629#M137020</link>
      <description>Which likely means it's either a source data issue or something we're not seeing (previous code) that's causing the issues. &lt;BR /&gt;&lt;BR /&gt;FYI - you can speed this up by using temporary arrays and loading them from a data set if you have it or using a format which would be significantly faster.</description>
      <pubDate>Thu, 01 Nov 2018 17:51:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Supposed-Array-Character-Missassignment/m-p/509629#M137020</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-11-01T17:51:29Z</dc:date>
    </item>
    <item>
      <title>Re: Supposed Array Character Missassignment</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Supposed-Array-Character-Missassignment/m-p/509630#M137021</link>
      <description>&lt;P&gt;A couple of small pieces just to get them out of the way:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since you need a set of constants, not a set of variables, make the array elements temporary:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;array secgen {192} $ _temporary_ (..................................);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And confirm that NDCNUM is actually character.&amp;nbsp; If it's numeric, the quotes around the array elements should be removed.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Nov 2018 17:52:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Supposed-Array-Character-Missassignment/m-p/509630#M137021</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-11-01T17:52:45Z</dc:date>
    </item>
    <item>
      <title>Re: Supposed Array Character Missassignment</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Supposed-Array-Character-Missassignment/m-p/509631#M137022</link>
      <description>&lt;P&gt;Ah! Sorry. I have a tab deliminted text file attached. There are some other data, but this is all I'm actively using in my process. The array data is extracted from another file that has been verified as correct and the ndcnum data is what I'd like to check.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Nov 2018 17:54:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Supposed-Array-Character-Missassignment/m-p/509631#M137022</guid>
      <dc:creator>jdchang</dc:creator>
      <dc:date>2018-11-01T17:54:14Z</dc:date>
    </item>
    <item>
      <title>Re: Supposed Array Character Missassignment</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Supposed-Array-Character-Missassignment/m-p/509633#M137024</link>
      <description>What's the type, length and format of the ndcnum variable?</description>
      <pubDate>Thu, 01 Nov 2018 17:56:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Supposed-Array-Character-Missassignment/m-p/509633#M137024</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-11-01T17:56:08Z</dc:date>
    </item>
    <item>
      <title>Re: Supposed Array Character Missassignment</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Supposed-Array-Character-Missassignment/m-p/509634#M137025</link>
      <description>&lt;P&gt;If you insist on arrays perhaps something like:&lt;/P&gt;
&lt;PRE&gt;data example;
   input readvariable $;
   array categoryone (4) $ 1 _temporary_ ("a", "b", "c", "d");
   array categorytwo (3) $ 3 _temporary_  ("aaa", "aab", "aac");
   length category $ 4;
   if whichc(readvariable,of categoryone(*)) &amp;gt; 0 then category='1';
   else if whichc(readvariable,of categorytwo(*)) &amp;gt; 0 then category='2';
   else category='None';

datalines;
a
b
q
aaa
aac
bbb
;
run;&lt;/PRE&gt;
&lt;P&gt;Though I would be more likely to do something like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc format library=work;
value $cat
"a", "b", "c", "d"= '1'
"aaa", "aab", "aac"='2'
other='None'
;
run;
data example2;
   input readvariable $;
   category = put(readvariable,$cat.);
datalines;
a
b
q
aaa
aac
bbb
;
run;&lt;/PRE&gt;
&lt;P&gt;Especially if your values you are currently placing in the arrays are available in a data set as formats can be built from datasets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or even instead of assignment of a new variable just use the format as needed.&lt;/P&gt;
&lt;PRE&gt;proc freq data=example2;
   tables readvariable;
   format readvariable $cat.;
run;&lt;/PRE&gt;
&lt;P&gt;Categories assigned by formats are honored by&amp;nbsp; almost all of the SAS analysis procedures.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Nov 2018 17:58:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Supposed-Array-Character-Missassignment/m-p/509634#M137025</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-11-01T17:58:56Z</dc:date>
    </item>
  </channel>
</rss>

