<?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 Array recoding incorrect value in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Array-recoding-incorrect-value/m-p/717477#M221889</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;So I am working with a dataset that includes 169 numeric variables which can take the values of . (not observed), 0 (no outcome), or 1+ (number of outcomes). I am using an array to recode these variables to use as predictors in PROC GENMOD and want the variables take the values of 1 (outcome present), 2 (outcome absent), and . (not observed). However, I noticed that variables which had no outcome observed were showing an outcome after using the following code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data insp_test;
merge data.data_micro data.data_insp_hist_w12;&lt;BR /&gt;by ESTID COLLECTDT;
ARRAY dcharr (*) R301_002--R550_001;
do i = 1 to dim(dcharr);
	if dcharr(i) &amp;gt; 0 then dcharr(i) = 1; else 
	if dcharr(i) = 0 then dcharr(i) = 2; else
	dcharr(i) = .;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I have checked the input and output datasets multiple times and I know the error results during this stage of processing. I am confused because the error does not carry over within the variable, but all variable values of 0 within an observation (8 of 40,497 obs) are recoded to have a value of 1 in the output dataset (instead of 2).&lt;/P&gt;&lt;P&gt;I would greatly appreciate any input on whether this is an issue stemming from my code or if there is some underlying feature of SAS that I do not know about at play here.&lt;/P&gt;</description>
    <pubDate>Mon, 08 Feb 2021 03:27:43 GMT</pubDate>
    <dc:creator>atbeczkiewicz</dc:creator>
    <dc:date>2021-02-08T03:27:43Z</dc:date>
    <item>
      <title>Array recoding incorrect value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-recoding-incorrect-value/m-p/717477#M221889</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;So I am working with a dataset that includes 169 numeric variables which can take the values of . (not observed), 0 (no outcome), or 1+ (number of outcomes). I am using an array to recode these variables to use as predictors in PROC GENMOD and want the variables take the values of 1 (outcome present), 2 (outcome absent), and . (not observed). However, I noticed that variables which had no outcome observed were showing an outcome after using the following code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data insp_test;
merge data.data_micro data.data_insp_hist_w12;&lt;BR /&gt;by ESTID COLLECTDT;
ARRAY dcharr (*) R301_002--R550_001;
do i = 1 to dim(dcharr);
	if dcharr(i) &amp;gt; 0 then dcharr(i) = 1; else 
	if dcharr(i) = 0 then dcharr(i) = 2; else
	dcharr(i) = .;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I have checked the input and output datasets multiple times and I know the error results during this stage of processing. I am confused because the error does not carry over within the variable, but all variable values of 0 within an observation (8 of 40,497 obs) are recoded to have a value of 1 in the output dataset (instead of 2).&lt;/P&gt;&lt;P&gt;I would greatly appreciate any input on whether this is an issue stemming from my code or if there is some underlying feature of SAS that I do not know about at play here.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Feb 2021 03:27:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-recoding-incorrect-value/m-p/717477#M221889</guid>
      <dc:creator>atbeczkiewicz</dc:creator>
      <dc:date>2021-02-08T03:27:43Z</dc:date>
    </item>
    <item>
      <title>Re: Array recoding incorrect value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-recoding-incorrect-value/m-p/717487#M221894</link>
      <description>&lt;P&gt;1. Show the log and the output from a proc freq for the before/after values. Use a second array to remap to ensure that your code is clean.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. Try using the ROUND() function to round your values to the nearest integer before comparison, you may be having floating point issues.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3. I'm assuming the original variable was numeric, but if it was character you need to modify your code to correctly account for that. You say 1+ below, but not sure if that's the actual value or if that indicates a number greater than 1.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/268361"&gt;@atbeczkiewicz&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;So I am working with a dataset that includes 169 numeric variables which can take the values of . (not observed), 0 (no outcome), or 1+ (number of outcomes).&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Feb 2021 04:28:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-recoding-incorrect-value/m-p/717487#M221894</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-02-08T04:28:08Z</dc:date>
    </item>
    <item>
      <title>Re: Array recoding incorrect value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-recoding-incorrect-value/m-p/717503#M221902</link>
      <description>&lt;P&gt;One might also suggest providing some details on exactly how you " checked the input and output datasets".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What are the current formats assigned to the variables? Sometimes "looking" at a table or printing the values, both of which will use the current default format will hide the fact that there are decimal values involved that "look" like 0 when they are are actually .009 or such.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Feb 2021 17:58:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-recoding-incorrect-value/m-p/717503#M221902</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-02-08T17:58:57Z</dc:date>
    </item>
    <item>
      <title>Re: Array recoding incorrect value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-recoding-incorrect-value/m-p/717511#M221906</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/268361"&gt;@atbeczkiewicz&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There's another risk in code like yours which combines &lt;EM&gt;merging&lt;/EM&gt; and &lt;EM&gt;recoding&lt;/EM&gt;: If the merge is not 1:1, observations with duplicate key values might be recoded &lt;EM&gt;twice&lt;/EM&gt;, leading to exactly the effect you've observed, i.e., the recoding changes&amp;nbsp;&lt;STRONG&gt;0&lt;/STRONG&gt; → 2 → &lt;STRONG&gt;1&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Simplified example (based on your code):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data micro;
input estid collectdt r301 r400 r550;
cards;
1 20000 . 0 5
;

data hist;
input estid collectdt histvar $;
cards;
1 20000 A
1 20000 B
;

data insp_wrong;
merge micro hist;
by estid collectdt;
array dcharr(*) r301--r550;
do i = 1 to dim(dcharr);
  if dcharr(i) &amp;gt; 0 then dcharr(i) = 1; else 
  if dcharr(i) = 0 then dcharr(i) = 2; else
  dcharr(i) = .;
end;
drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;&lt;FONT size="4"&gt;Obs    estid    collectdt    r301    r400    r550    histvar

 1       1        20000        .       2       1        A
 2       1        20000        .       &lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;       1        B&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;Safest solution in this situation: Separate the MERGE step from the recoding step, i.e., the recoding step will use a SET statement reading the dataset created in the preceding MERGE step. Of course, you need to make sure that observations with duplicate key values (&lt;FONT face="courier new,courier"&gt;estid collectdt&lt;/FONT&gt;) are handled correctly according to the requirements.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Feb 2021 08:52:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-recoding-incorrect-value/m-p/717511#M221906</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-02-08T08:52:43Z</dc:date>
    </item>
  </channel>
</rss>

