<?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: using array to recode observations in multiple variables in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/using-array-to-recode-observations-in-multiple-variables/m-p/773223#M31150</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;Be glad that you have not had reason to learn about (or worse experience)&amp;nbsp;&lt;SPAN&gt;congestive heart failure.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Sat, 09 Oct 2021 16:25:58 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2021-10-09T16:25:58Z</dc:date>
    <item>
      <title>using array to recode observations in multiple variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/using-array-to-recode-observations-in-multiple-variables/m-p/773218#M31148</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data thcics.question8;
    input $ admitting_diag princ_diag_code oth_diag_code1  oth_diag_code2 ;
datalines;

v350       25001                  4567
25001     v4001                  v4001
v3560     5670      418
2502       v4000
v4000     25032
e560       4352     v3201
518         5670
25029     A1054                6530 
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data thcics.question8;
set thcics.thcicsamp;
ID = _N_;
DIABETES = 0;
CHF = 0;
keep ID DIABETES CHF discharge thcic_id length_of_stay provider_name Admitting_Diag  Princ_Diag_Code  Oth_Diag_Code2-Oth_Diag_Code10;
array A (*)$5 Admitting_Diag  Princ_Diag_Code Oth_Diag_Code2-Oth_Diag_Code10;
do i = 1 to dim(A);
diagnosis = A(i);
IF diagnosis = '39891' OR diagnosis = '40201' OR diagnosis = '40211' OR                                                                            
    diagnosis = '40291' OR diagnosis = '40401' OR diagnosis = '40403' OR                                                                            
    diagnosis = '40411' OR diagnosis = '40413' OR diagnosis = '40491' OR                                                                            
    diagnosis = '40493' OR SUBSTR(diagnosis,1,4)='4251' OR                                                                                     
    SUBSTR(diagnosis,1,4)='4254' OR SUBSTR(diagnosis,1,4)='4255' OR                                                                            
    SUBSTR(diagnosis,1,4)='4259' OR SUBSTR(diagnosis,1,4)='4280' OR                                                                            
    SUBSTR(diagnosis,1,4)='4281' OR SUBSTR(diagnosis,1,4)='4289'                                                                               
  then CHF=1; 
else CHF = 0;
 label chf = 'chf';
IF substr (diagnosis,1,3) IN: ('250') then diabetes = 1;
else diabetes = 0;
label diabetes = 'diabetes';
          
end;
end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Hello everyone,&lt;/P&gt;
&lt;P&gt;please I have a challenge, I want to code some observations in 10 of my variables ( diagnosis variables containing disease types in codes) to chronic heart failure (chf) and diabetes and then get the number of patients with chf and diabetes. my log shows no error but i oberved that all my chf and diabetes variable was 0 even if the variables had the code for them. my variables from oth_diag_code1-10 was also blank. I will appreciate if you can please help me fish out what is wrong with my syntax. Thanks a lot, as always&lt;/P&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="10%"&gt;ID&lt;/TD&gt;
&lt;TD width="10%"&gt;THCIC_ID&lt;/TD&gt;
&lt;TD width="10%"&gt;admitting_diag&lt;/TD&gt;
&lt;TD width="10%"&gt;princ_diag_code&lt;/TD&gt;
&lt;TD width="10%"&gt;oth_diag_code_1&lt;/TD&gt;
&lt;TD width="10%"&gt;oth_diag_code_2&lt;/TD&gt;
&lt;TD width="10%"&gt;oth_diag_code_3&lt;/TD&gt;
&lt;TD width="10%"&gt;oth_diag_code_10&lt;/TD&gt;
&lt;TD width="10%"&gt;diabetes&lt;/TD&gt;
&lt;TD width="10%"&gt;chf&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="10%"&gt;1&lt;/TD&gt;
&lt;TD width="10%"&gt;1001&lt;/TD&gt;
&lt;TD width="10%"&gt;v0291&lt;/TD&gt;
&lt;TD width="10%"&gt;25010&lt;/TD&gt;
&lt;TD width="10%"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="10%"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="10%"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="10%"&gt;25021&lt;/TD&gt;
&lt;TD width="10%"&gt;1&lt;/TD&gt;
&lt;TD width="10%"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="10%"&gt;2&lt;/TD&gt;
&lt;TD width="10%"&gt;1001&lt;/TD&gt;
&lt;TD width="10%"&gt;40291&lt;/TD&gt;
&lt;TD width="10%"&gt;40291&lt;/TD&gt;
&lt;TD width="10%"&gt;39891&lt;/TD&gt;
&lt;TD width="10%"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="10%"&gt;4255&lt;/TD&gt;
&lt;TD width="10%"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="10%"&gt;0&lt;/TD&gt;
&lt;TD width="10%"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="10%"&gt;3&lt;/TD&gt;
&lt;TD width="10%"&gt;1002&lt;/TD&gt;
&lt;TD width="10%"&gt;39891&lt;/TD&gt;
&lt;TD width="10%"&gt;40493&lt;/TD&gt;
&lt;TD width="10%"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="10%"&gt;25053&lt;/TD&gt;
&lt;TD width="10%"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="10%"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="10%"&gt;1&lt;/TD&gt;
&lt;TD width="10%"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="10%"&gt;4&lt;/TD&gt;
&lt;TD width="10%"&gt;1003&lt;/TD&gt;
&lt;TD width="10%"&gt;25001&lt;/TD&gt;
&lt;TD width="10%"&gt;25002&lt;/TD&gt;
&lt;TD width="10%"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="10%"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="10%"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="10%"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="10%"&gt;1&lt;/TD&gt;
&lt;TD width="10%"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Oct 2021 14:40:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/using-array-to-recode-observations-in-multiple-variables/m-p/773218#M31148</guid>
      <dc:creator>Banke</dc:creator>
      <dc:date>2021-10-09T14:40:23Z</dc:date>
    </item>
    <item>
      <title>Re: using array to recode observations in multiple variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/using-array-to-recode-observations-in-multiple-variables/m-p/773222#M31149</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;i oberved that all my chf and diabetes variable was 0 even if the variables had the code for them. my variables from oth_diag_code1-10 was also blank. I will appreciate if you can please help me fish out what is wrong with my syntax.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is because the last step in the IF-THEN-ELSE construct &lt;FONT face="courier new,courier"&gt;else chf=0&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;else diabetes=0&lt;/FONT&gt; the way you wrote it sets variables CHF and DIABETES to zero. By removing those lines, you should get what you want. Also please note the proper indentation of your code makes everything easier to understand and debug and to see if you have the proper matching DO with END (which you don't have)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data thcics.question8;
    set thcics.thcicsamp;
    ID = _N_;
    DIABETES = 0;
    CHF = 0;
    keep ID DIABETES CHF discharge thcic_id length_of_stay 
        provider_name Admitting_Diag Princ_Diag_Code Oth_Diag_Code2-Oth_Diag_Code10;
    array A (*)$5 Admitting_Diag  Princ_Diag_Code Oth_Diag_Code2-Oth_Diag_Code10;
    do i = 1 to dim(A);
        IF a(i)= '39891' OR a(i)= '40201' OR a(i)= '40211' OR                                                                            
            a(i)= '40291' OR a(i)= '40401' OR a(i)= '40403' OR                                                                            
            a(i)= '40411' OR a(i)= '40413' OR a(i)= '40491' OR                                                                            
            a(i)= '40493' OR substr(a(i),1,4)='4251' OR                                                                                     
            SUBSTR(a(i),1,4)='4254' OR SUBSTR(a(i),1,4)='4255' OR                                                                            
            SUBSTR(a(i),1,4)='4259' OR SUBSTR(a(i),1,4)='4280' OR                                                                            
            SUBSTR(a(i),1,4)='4281' OR SUBSTR(a(i),1,4)='4289'                                                                               
            then CHF=1; 
        IF substr (a(i),1,3) IN: ('250') then diabetes = 1;      
    end;
end;  /* THERE IS NO DO FOR THIS END, THIS SHOULD CAUSE AN ERROR */
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I also question the purpose and logic behind these statements:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;label diabetes = 'diabetes';
label chf='chf';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Usually (in fact ALWAYS), labels are meant to make the output readable. There's really no reason to assign a label of 'chf' to chf, this enhances nothing. You might want to use proper capitalization in your label, that would make things more readable. Or if CHF is an acronym (I don't really know what it means, it may be that in your industry everyone knows what CHF is and so no need to spell out the words of the acronym, but I will give an example anyway)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;label diabetes='Diabetes'; /* Note proper capitalization */
label chf='Chicago Hostile Ferengi'; /* OPTIONAL: Spell out the acronym */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Oct 2021 16:20:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/using-array-to-recode-observations-in-multiple-variables/m-p/773222#M31149</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-10-09T16:20:01Z</dc:date>
    </item>
    <item>
      <title>Re: using array to recode observations in multiple variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/using-array-to-recode-observations-in-multiple-variables/m-p/773223#M31150</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;Be glad that you have not had reason to learn about (or worse experience)&amp;nbsp;&lt;SPAN&gt;congestive heart failure.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Oct 2021 16:25:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/using-array-to-recode-observations-in-multiple-variables/m-p/773223#M31150</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-10-09T16:25:58Z</dc:date>
    </item>
    <item>
      <title>Re: using array to recode observations in multiple variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/using-array-to-recode-observations-in-multiple-variables/m-p/773224#M31151</link>
      <description>&lt;P&gt;The way you structured your loop is only testing the last element in the array.&lt;/P&gt;
&lt;P&gt;So this code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;x=0;
do index=1 to dim(array);
   if array[index]='xxx' then x=1;
   else x=0;
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Is the same as:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if array[dim(array)]='xxx' then x=1;
else x=0;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So remove the ELSE statement(s).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  do i = 1 to dim(A);
    if a[i] in: ('39891' '40201' '40211' '40291' '40401' '40403' 
                '40411' '40413' '40491' '40493' 
                '4251' '4254' '4255' '4259' '4280' '4281' '4289'
                )  
       then CHF=1
    ; 
    if a[i] in: ('250') then diabetes = 1;
  end;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 09 Oct 2021 16:41:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/using-array-to-recode-observations-in-multiple-variables/m-p/773224#M31151</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-10-09T16:41:28Z</dc:date>
    </item>
    <item>
      <title>Re: using array to recode observations in multiple variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/using-array-to-recode-observations-in-multiple-variables/m-p/773225#M31152</link>
      <description>&lt;P&gt;Thank you so much&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;,&amp;nbsp; I understand it better now. I had even intialized a value of zero to the variables. Thank you for the tips on labelling and identation. The second "run;" is an error,&amp;nbsp; sorry about that.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Oct 2021 16:57:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/using-array-to-recode-observations-in-multiple-variables/m-p/773225#M31152</guid>
      <dc:creator>Banke</dc:creator>
      <dc:date>2021-10-09T16:57:39Z</dc:date>
    </item>
    <item>
      <title>Re: using array to recode observations in multiple variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/using-array-to-recode-observations-in-multiple-variables/m-p/773226#M31153</link>
      <description>thanks so much</description>
      <pubDate>Sat, 09 Oct 2021 16:58:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/using-array-to-recode-observations-in-multiple-variables/m-p/773226#M31153</guid>
      <dc:creator>Banke</dc:creator>
      <dc:date>2021-10-09T16:58:53Z</dc:date>
    </item>
    <item>
      <title>Re: using array to recode observations in multiple variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/using-array-to-recode-observations-in-multiple-variables/m-p/773240#M31155</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;and everyone, please, is it possible to use array to get the top most frequent diagnosis (i.e the top 5 frequent observations in my array elements)? thanks&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Oct 2021 22:38:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/using-array-to-recode-observations-in-multiple-variables/m-p/773240#M31155</guid>
      <dc:creator>Banke</dc:creator>
      <dc:date>2021-10-09T22:38:15Z</dc:date>
    </item>
    <item>
      <title>Re: using array to recode observations in multiple variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/using-array-to-recode-observations-in-multiple-variables/m-p/773242#M31156</link>
      <description>&lt;OL&gt;
&lt;LI&gt;Use PROC TRANSPOSE to place all of the diagnosis codes into a single column.&lt;/LI&gt;
&lt;LI&gt;Use PROC FREQ on this new single column to obtain the counts for each diagnosis code.&lt;/LI&gt;
&lt;LI&gt;Sort the counts so the top 5 are available.&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Sat, 09 Oct 2021 23:12:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/using-array-to-recode-observations-in-multiple-variables/m-p/773242#M31156</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-10-09T23:12:45Z</dc:date>
    </item>
    <item>
      <title>Re: using array to recode observations in multiple variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/using-array-to-recode-observations-in-multiple-variables/m-p/773266#M31157</link>
      <description>&lt;P&gt;brilliant! thanks a lot. It worked&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data thcics.question4;
    set thcics.thcicsamp;
         ID = _N_;
   keep  ID thcic_id length_of_stay provider_name Admitting_Diag Princ_Diag_Code Oth_Diag_Code_1-Oth_Diag_Code_8;
run;

proc transpose data = thcics.question4 out = thcics.question4a name = alldiag;
by id;
var Admitting_Diag Princ_Diag_Code Oth_Diag_Code_1-Oth_Diag_Code_8;
run;

proc freq data = thcics.question4a;
tables col1 / out = thcics.freq4a;
run;

proc sort data = thcics.freq4a;
by descending count;
run;
proc print data = thcics.freq4b (firstobs=2 obs=6);
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 10 Oct 2021 13:27:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/using-array-to-recode-observations-in-multiple-variables/m-p/773266#M31157</guid>
      <dc:creator>Banke</dc:creator>
      <dc:date>2021-10-10T13:27:47Z</dc:date>
    </item>
    <item>
      <title>Re: using array to recode observations in multiple variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/using-array-to-recode-observations-in-multiple-variables/m-p/773275#M31158</link>
      <description>&lt;P&gt;For what its worth, you can replace this code:&lt;/P&gt;
&lt;PRE&gt;IF a(i)= '39891' OR a(i)= '40201' OR a(i)= '40211' OR                                                                            
   a(i)= '40291' OR a(i)= '40401' OR a(i)= '40403' OR                                                                            
   a(i)= '40411' OR a(i)= '40413' OR a(i)= '40491' OR                                                                            
   a(i)= '40493' OR substr(a(i),1,4)='4251' OR                                                                                     
   SUBSTR(a(i),1,4)='4254' OR SUBSTR(a(i),1,4)='4255' OR                                                                            
   SUBSTR(a(i),1,4)='4259' OR SUBSTR(a(i),1,4)='4280' OR                                                                            
   SUBSTR(a(i),1,4)='4281' OR SUBSTR(a(i),1,4)='4289'                                                                               
   then CHF=1; 
&lt;/PRE&gt;
&lt;P&gt;With:&lt;/P&gt;
&lt;PRE&gt;if a(i) in ('39891' '40201' '40211' '40291' '40401' '40403' '40411' '40413' '40491' '40493')
   or substr(a(i),1,4) in ('4251' '4254' '4255' '4259' '4280' '4281' '4289')
   then CHF=1;
&lt;/PRE&gt;
&lt;P&gt;The IN operator will compare a variable or single expression to the list of values in the () and return a true/false result if the value matches any of them.&lt;/P&gt;
&lt;P&gt;May save some time typing code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 10 Oct 2021 16:39:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/using-array-to-recode-observations-in-multiple-variables/m-p/773275#M31158</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-10-10T16:39:34Z</dc:date>
    </item>
    <item>
      <title>Re: using array to recode observations in multiple variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/using-array-to-recode-observations-in-multiple-variables/m-p/773297#M31160</link>
      <description>Thank you so much, definitely saves more time and easier to read</description>
      <pubDate>Mon, 11 Oct 2021 00:11:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/using-array-to-recode-observations-in-multiple-variables/m-p/773297#M31160</guid>
      <dc:creator>Banke</dc:creator>
      <dc:date>2021-10-11T00:11:07Z</dc:date>
    </item>
  </channel>
</rss>

