<?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: Error/No Results in String Comparison using Array in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Error-No-Results-in-String-Comparison-using-Array/m-p/339367#M77412</link>
    <description>&lt;P&gt;For an array with character variables you do need to add the $ sign in the array statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The date line of the code is incorrect, but I don't know if that's pseudo code or real code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't think you've given us enough to answer your question.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your full array isn't shown - there's no end? Is there an else?&lt;/P&gt;
&lt;P&gt;If there's an error include.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Ideally, post some data that allows us to replicate the issue.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another formula that's useful for this is WHICHC(). And another method is to use a format to check the diagnosis list.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 08 Mar 2017 19:18:44 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2017-03-08T19:18:44Z</dc:date>
    <item>
      <title>Error/No Results in String Comparison using Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-No-Results-in-String-Comparison-using-Array/m-p/339357#M77410</link>
      <description>&lt;P&gt;Hi all, using sas 9.4 on a windows platform (coming to SAS from C/C++ and Python background):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm using an array to compare a string variable with a list of strings to set a flag variable. This code works for a single variable, and it works in a different dataset (basically the same code) but when I try to use it with this dataset I am not getting any results.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's the main idea (pseudo-sas):&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;    if this_one_code IN: (&amp;lt;list of strings&amp;gt;) then do;
        flag = 1;
        date = this_date
    end;
/* The above works fine and the flags are set for valid variables */&lt;BR /&gt;&lt;BR /&gt;/* now I try the same over the other codes: */
    array dx(24) code2-code25;
    do i = 1 to 24;
        if dx[i] IN: (&amp;lt;list of strings&amp;gt;) then do;
	    flag = 2;
            date = this date;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;When I hit&amp;nbsp;this array though, I get errors of "character values converted to numeric" for every conditional inside the array do block.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It works without the dollar sign in another program using the same code and string variable lists. I thought SAS would be smart enough to get the string implicitly but I guess that's not the case.&lt;/P&gt;&lt;P&gt;I tried correcting this by adding the $ before the variable:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;    array dx(24) $code2-code25;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This silences the error, but I get no results from the logic in the loop.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I would like&amp;nbsp;to know is:&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is this array declaration for an array of strings correct? If not, what should I do to correct?&lt;/P&gt;&lt;P&gt;Are there any other noticable issues?&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Mar 2017 19:18:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-No-Results-in-String-Comparison-using-Array/m-p/339357#M77410</guid>
      <dc:creator>tbendubois</dc:creator>
      <dc:date>2017-03-08T19:18:33Z</dc:date>
    </item>
    <item>
      <title>Re: Error/No Results in String Comparison using Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-No-Results-in-String-Comparison-using-Array/m-p/339367#M77412</link>
      <description>&lt;P&gt;For an array with character variables you do need to add the $ sign in the array statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The date line of the code is incorrect, but I don't know if that's pseudo code or real code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't think you've given us enough to answer your question.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your full array isn't shown - there's no end? Is there an else?&lt;/P&gt;
&lt;P&gt;If there's an error include.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Ideally, post some data that allows us to replicate the issue.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another formula that's useful for this is WHICHC(). And another method is to use a format to check the diagnosis list.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Mar 2017 19:18:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-No-Results-in-String-Comparison-using-Array/m-p/339367#M77412</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-03-08T19:18:44Z</dc:date>
    </item>
    <item>
      <title>Re: Error/No Results in String Comparison using Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-No-Results-in-String-Comparison-using-Array/m-p/339378#M77414</link>
      <description>&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token statement"&gt;array&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;dx&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;24&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; code2&lt;SPAN class="token operator"&gt;-&lt;/SPAN&gt;code25&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
do i &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;1&lt;/SPAN&gt; to &lt;SPAN class="token number"&gt;24&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;    if&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;dx&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;[&lt;/SPAN&gt;i&lt;SPAN class="token punctuation"&gt;]&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;IN&lt;/SPAN&gt;: &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;&amp;lt;&lt;/SPAN&gt;list of strings&lt;SPAN class="token operator"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;then&lt;/SPAN&gt; do&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
        flag &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;2&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
        &lt;SPAN class="token function"&gt;date&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; this_&lt;SPAN class="token function"&gt;date&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;BR /&gt;    end;&lt;BR /&gt;end;&lt;BR /&gt;/* I repeat the above about seven times with a different list of strings*/&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Edit: The formatting is broken above. The ends should be on newlines&lt;/P&gt;&lt;P&gt;The array ends after a bunch of conditionals as shown above.&lt;/P&gt;&lt;P&gt;However, I did as you suggested and made up some code for testing and it appears to run fine:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data code;
	length code1 code2 code3 code4 $2;
	input code1 code2 code3 code4;
	datalines;
A1 A2 A3 A4
B1 B2 B3 B4
C1 C2 C3 C4
;

data code_check (drop=i);
	set code;
	flag1 = 0;
	flag234 = 0;
	if code1 IN: ("A1", "B1", "C1") then flag1 = 1;
	array dx(3) $code2-code4;
	do i = 1 to 3;
		if dx[i] IN: ("A2", "B2") then flag234 = 1;
	end;
	run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I wonder if I might be dealing with a data issue instead now. I will have to take a look.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Mar 2017 19:41:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-No-Results-in-String-Comparison-using-Array/m-p/339378#M77414</guid>
      <dc:creator>tbendubois</dc:creator>
      <dc:date>2017-03-08T19:41:16Z</dc:date>
    </item>
    <item>
      <title>Re: Error/No Results in String Comparison using Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-No-Results-in-String-Comparison-using-Array/m-p/339384#M77419</link>
      <description>&lt;P&gt;The symptoms you describe are consistent with CODE2 - CODE25 being the wrong variable names.&amp;nbsp; Perhaps in the original data they were something similar, like CODE_2 - CODE_25.&amp;nbsp; Use whatever names are actually in your data set.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Mar 2017 19:53:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-No-Results-in-String-Comparison-using-Array/m-p/339384#M77419</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-03-08T19:53:42Z</dc:date>
    </item>
    <item>
      <title>Re: Error/No Results in String Comparison using Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-No-Results-in-String-Comparison-using-Array/m-p/339389#M77421</link>
      <description>&lt;P&gt;It's almost like you knew...&lt;BR /&gt;It was missing the underscore before the number.&lt;BR /&gt;I'll smack my head accordingly. Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there any way to get an error like that to show up? I'd think SAS would complain that the variable iterated over doesn't exist. Definitely didn't show up in any output.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Mar 2017 19:58:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-No-Results-in-String-Comparison-using-Array/m-p/339389#M77421</guid>
      <dc:creator>tbendubois</dc:creator>
      <dc:date>2017-03-08T19:58:58Z</dc:date>
    </item>
    <item>
      <title>Re: Error/No Results in String Comparison using Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-No-Results-in-String-Comparison-using-Array/m-p/339395#M77422</link>
      <description>&lt;P&gt;There's no error because the array statement can also be used to create new variables. So your array statement was referring to new variables but not the ones you wanted.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Mar 2017 20:01:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-No-Results-in-String-Comparison-using-Array/m-p/339395#M77422</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-03-08T20:01:20Z</dc:date>
    </item>
    <item>
      <title>Re: Error/No Results in String Comparison using Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-No-Results-in-String-Comparison-using-Array/m-p/339397#M77423</link>
      <description>Good to know. Thanks for that explanation.</description>
      <pubDate>Wed, 08 Mar 2017 20:02:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-No-Results-in-String-Comparison-using-Array/m-p/339397#M77423</guid>
      <dc:creator>tbendubois</dc:creator>
      <dc:date>2017-03-08T20:02:37Z</dc:date>
    </item>
    <item>
      <title>Re: Error/No Results in String Comparison using Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-No-Results-in-String-Comparison-using-Array/m-p/339432#M77426</link>
      <description>&lt;P&gt;The Log might have given you a clue with the number of variables in the ouput set. The log would have the number variables and if you notice there are 24 more than expected...&lt;/P&gt;</description>
      <pubDate>Wed, 08 Mar 2017 20:40:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-No-Results-in-String-Comparison-using-Array/m-p/339432#M77426</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-03-08T20:40:51Z</dc:date>
    </item>
  </channel>
</rss>

