<?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: Character variables are being converted to numeric, don't understand why. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Character-variables-are-being-converted-to-numeric-don-t/m-p/577776#M163759</link>
    <description>&lt;P&gt;I'm trying to set first_dx to the first matching diagnostic code listed in dx1-dx9. In the above example, that would be V1002 for obs 1, V1001 for obs 2, and S400X for obs 3. I think your code keeps running the do loop even after it finds a match, so first_dx is set to the last matching code.&lt;/P&gt;</description>
    <pubDate>Tue, 30 Jul 2019 15:03:15 GMT</pubDate>
    <dc:creator>megsredl</dc:creator>
    <dc:date>2019-07-30T15:03:15Z</dc:date>
    <item>
      <title>Character variables are being converted to numeric, don't understand why.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-variables-are-being-converted-to-numeric-don-t/m-p/577771#M163755</link>
      <description>&lt;P&gt;I have a list of diagnostic codes in variables dx1-dx9 for each observation. I'm trying to extract the first diagnostic code that matches a specified subset for each observation. Here's the basic structure of my data:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
	input dx1 $ dx2 $ dx3 $ dx4 $ dx5 $ dx6 $ dx7 $ dx8 $ dx9 $;
	datalines;
		D2002 O2829 V1002 T2000 W2018 . . . .
		B1080 V1001 S400X R2910 44323 I1088 FB372 X3007 A5850
		M5992 R6602 U2710 S400X D0412 V1002 C4010 . .
		;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This is the code I wrote:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data pwid.test;
	length first_dx $6;
	set pwid.test;
	array dxnum[9] dx1-dx9;
	do i = 1 to 9;
		if dxnum[i] not in ("V1001", "V1002", "S400X") then continue;
		else first_dx=dxnum[i] and leave;
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I'm getting a message for my "else" line that character values have been converted to numeric values and numeric values have been converted to character values, then I get an error message saying "invalid numeric data" (see screenshot). As far as I can tell everything should be a character variable, so I'm not sure why anything is getting converted to numeric. What's causing this issue? If there's a better way to write this code I'd appreciate that as well. Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture1.PNG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/31415i8244A068B080D958/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture1.PNG" alt="Capture1.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jul 2019 14:52:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-variables-are-being-converted-to-numeric-don-t/m-p/577771#M163755</guid>
      <dc:creator>megsredl</dc:creator>
      <dc:date>2019-07-30T14:52:52Z</dc:date>
    </item>
    <item>
      <title>Re: Character variables are being converted to numeric, don't understand why.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-variables-are-being-converted-to-numeric-don-t/m-p/577773#M163756</link>
      <description>&lt;P&gt;Not sure your exact objective, can i assume this is what you perhaps want?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test1;
	length first_dx $6;
	set test;
	array dxnum[9] dx1-dx9;
	do i = 1 to 9;
		if dxnum[i] not in ("V1001", "V1002", "S400X") then continue;
		else  first_dx=dxnum[i];
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 30 Jul 2019 14:57:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-variables-are-being-converted-to-numeric-don-t/m-p/577773#M163756</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-07-30T14:57:42Z</dc:date>
    </item>
    <item>
      <title>Re: Character variables are being converted to numeric, don't understand why.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-variables-are-being-converted-to-numeric-don-t/m-p/577774#M163757</link>
      <description>&lt;P&gt;Please read the entire log from this. Your problem is at line 189, column 23. What is there? At that location is a NUMERIC variable named LEAVE. You can't assign the value DXNUM[i] AND LEAVE to FIRST_DX, because DXNUM[i] is charcter and LEAVE is numeric and so the statement DXNUM[i] AND LEAVE cannot be evaluated.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jul 2019 15:01:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-variables-are-being-converted-to-numeric-don-t/m-p/577774#M163757</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-07-30T15:01:57Z</dc:date>
    </item>
    <item>
      <title>Re: Character variables are being converted to numeric, don't understand why.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-variables-are-being-converted-to-numeric-don-t/m-p/577776#M163759</link>
      <description>&lt;P&gt;I'm trying to set first_dx to the first matching diagnostic code listed in dx1-dx9. In the above example, that would be V1002 for obs 1, V1001 for obs 2, and S400X for obs 3. I think your code keeps running the do loop even after it finds a match, so first_dx is set to the last matching code.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jul 2019 15:03:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-variables-are-being-converted-to-numeric-don-t/m-p/577776#M163759</guid>
      <dc:creator>megsredl</dc:creator>
      <dc:date>2019-07-30T15:03:15Z</dc:date>
    </item>
    <item>
      <title>Re: Character variables are being converted to numeric, don't understand why.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-variables-are-being-converted-to-numeric-don-t/m-p/577777#M163760</link>
      <description>&lt;P&gt;Thanks, I figured that might be my problem. How can I exit the do loop at that point since leave doesn't work?&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jul 2019 15:04:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-variables-are-being-converted-to-numeric-don-t/m-p/577777#M163760</guid>
      <dc:creator>megsredl</dc:creator>
      <dc:date>2019-07-30T15:04:32Z</dc:date>
    </item>
    <item>
      <title>Re: Character variables are being converted to numeric, don't understand why.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-variables-are-being-converted-to-numeric-don-t/m-p/577780#M163761</link>
      <description>Try: &lt;BR /&gt;else do; &lt;BR /&gt; first_dx=dxnum[i];&lt;BR /&gt; leave;&lt;BR /&gt;end;</description>
      <pubDate>Tue, 30 Jul 2019 15:09:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-variables-are-being-converted-to-numeric-don-t/m-p/577780#M163761</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2019-07-30T15:09:24Z</dc:date>
    </item>
    <item>
      <title>Re: Character variables are being converted to numeric, don't understand why.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-variables-are-being-converted-to-numeric-don-t/m-p/577782#M163762</link>
      <description>Thank you so much!</description>
      <pubDate>Tue, 30 Jul 2019 15:10:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-variables-are-being-converted-to-numeric-don-t/m-p/577782#M163762</guid>
      <dc:creator>megsredl</dc:creator>
      <dc:date>2019-07-30T15:10:36Z</dc:date>
    </item>
    <item>
      <title>Re: Character variables are being converted to numeric, don't understand why.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-variables-are-being-converted-to-numeric-don-t/m-p/577783#M163763</link>
      <description>&lt;P&gt;I would recommend this variation:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
	do i = 1 to 9 until (first_dx &amp;gt; ' ');
		if dxnum[i] in ("V1001", "V1002", "S400X") then 
		first_dx=dxnum[i];
	end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 30 Jul 2019 15:12:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-variables-are-being-converted-to-numeric-don-t/m-p/577783#M163763</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-07-30T15:12:12Z</dc:date>
    </item>
    <item>
      <title>Re: Character variables are being converted to numeric, don't understand why.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-variables-are-being-converted-to-numeric-don-t/m-p/577785#M163764</link>
      <description>&lt;P&gt;Forget about LEAVE and CONTINUE.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Tell the DO statement what criteria to use to end the looping.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data pwid.test;
  set pwid.test;
  array dxnum[9] dx1-dx9;
  length first_dx $6;
  do i = 1 to 9 until(not missing(first_dx));
    if dxnum[i] in ("V1001", "V1002", "S400X") then first_dx=dxnum[i];
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 30 Jul 2019 15:13:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-variables-are-being-converted-to-numeric-don-t/m-p/577785#M163764</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-07-30T15:13:09Z</dc:date>
    </item>
    <item>
      <title>Re: Character variables are being converted to numeric, don't understand why.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-variables-are-being-converted-to-numeric-don-t/m-p/577793#M163767</link>
      <description>&lt;P&gt;Thanks for the help, this syntax is much more straightforward.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jul 2019 15:33:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-variables-are-being-converted-to-numeric-don-t/m-p/577793#M163767</guid>
      <dc:creator>megsredl</dc:creator>
      <dc:date>2019-07-30T15:33:38Z</dc:date>
    </item>
  </channel>
</rss>

