<?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 Using array to loop through all possible races in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-array-to-loop-through-all-possible-races/m-p/847876#M335202</link>
    <description>&lt;P&gt;I'm not new to SAS, but new to using arrays. I have a SAS table set up like this except for the final_race variable, which is what i want:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE border="1" width="100.16638616891065%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="12.5%" height="30px"&gt;patient_id&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;race_white&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;race_black&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;race_asian&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;race_am_indian&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;race_pac_islander&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;race_other&lt;/TD&gt;
&lt;TD width="6.25%" height="30px"&gt;race_unk&lt;/TD&gt;
&lt;TD width="6.25%" height="30px"&gt;final_race&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="12.5%" height="30px"&gt;1&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;1&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;0&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;0&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;0&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;0&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;0&lt;/TD&gt;
&lt;TD width="6.25%" height="30px"&gt;0&lt;/TD&gt;
&lt;TD width="6.25%" height="30px"&gt;white&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="12.5%" height="30px"&gt;2&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;1&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;1&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;0&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;0&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;0&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;0&lt;/TD&gt;
&lt;TD width="6.25%" height="30px"&gt;0&lt;/TD&gt;
&lt;TD width="6.25%" height="30px"&gt;multiracial&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="12.5%" height="30px"&gt;3&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;0&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;0&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;0&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;0&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;0&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;0&lt;/TD&gt;
&lt;TD width="6.25%" height="30px"&gt;0&lt;/TD&gt;
&lt;TD width="6.25%" height="30px"&gt;unknown&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="12.5%" height="30px"&gt;4&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;0&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;0&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;1&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;0&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;0&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;0&lt;/TD&gt;
&lt;TD width="6.25%" height="30px"&gt;0&lt;/TD&gt;
&lt;TD width="6.25%" height="30px"&gt;asian&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A 1 means a person is of that race. Some people could have 1s in multiple columns because they're multiracial. Some have all 0s meaning we don't know their race.&amp;nbsp; I need to sort through all the combos.. if a person has a 1 for only one race, then I need final_race to be that race. Else, if there are multiple 1s, then final_race "Multiracial". If all 0s, then "Unknown".&amp;nbsp; I tried to build something off&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Procedures/Race-looping/td-p/182117" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/SAS-Procedures/Race-looping/td-p/182117&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;but I couldn't figure it out with the differences I need.&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;</description>
    <pubDate>Mon, 05 Dec 2022 19:04:05 GMT</pubDate>
    <dc:creator>vegan_renegade</dc:creator>
    <dc:date>2022-12-05T19:04:05Z</dc:date>
    <item>
      <title>Using array to loop through all possible races</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-array-to-loop-through-all-possible-races/m-p/847876#M335202</link>
      <description>&lt;P&gt;I'm not new to SAS, but new to using arrays. I have a SAS table set up like this except for the final_race variable, which is what i want:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE border="1" width="100.16638616891065%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="12.5%" height="30px"&gt;patient_id&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;race_white&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;race_black&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;race_asian&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;race_am_indian&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;race_pac_islander&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;race_other&lt;/TD&gt;
&lt;TD width="6.25%" height="30px"&gt;race_unk&lt;/TD&gt;
&lt;TD width="6.25%" height="30px"&gt;final_race&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="12.5%" height="30px"&gt;1&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;1&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;0&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;0&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;0&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;0&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;0&lt;/TD&gt;
&lt;TD width="6.25%" height="30px"&gt;0&lt;/TD&gt;
&lt;TD width="6.25%" height="30px"&gt;white&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="12.5%" height="30px"&gt;2&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;1&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;1&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;0&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;0&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;0&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;0&lt;/TD&gt;
&lt;TD width="6.25%" height="30px"&gt;0&lt;/TD&gt;
&lt;TD width="6.25%" height="30px"&gt;multiracial&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="12.5%" height="30px"&gt;3&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;0&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;0&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;0&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;0&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;0&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;0&lt;/TD&gt;
&lt;TD width="6.25%" height="30px"&gt;0&lt;/TD&gt;
&lt;TD width="6.25%" height="30px"&gt;unknown&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="12.5%" height="30px"&gt;4&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;0&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;0&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;1&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;0&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;0&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;0&lt;/TD&gt;
&lt;TD width="6.25%" height="30px"&gt;0&lt;/TD&gt;
&lt;TD width="6.25%" height="30px"&gt;asian&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A 1 means a person is of that race. Some people could have 1s in multiple columns because they're multiracial. Some have all 0s meaning we don't know their race.&amp;nbsp; I need to sort through all the combos.. if a person has a 1 for only one race, then I need final_race to be that race. Else, if there are multiple 1s, then final_race "Multiracial". If all 0s, then "Unknown".&amp;nbsp; I tried to build something off&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Procedures/Race-looping/td-p/182117" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/SAS-Procedures/Race-looping/td-p/182117&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;but I couldn't figure it out with the differences I need.&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Mon, 05 Dec 2022 19:04:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-array-to-loop-through-all-possible-races/m-p/847876#M335202</guid>
      <dc:creator>vegan_renegade</dc:creator>
      <dc:date>2022-12-05T19:04:05Z</dc:date>
    </item>
    <item>
      <title>Re: Using array to loop through all possible races</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-array-to-loop-through-all-possible-races/m-p/847878#M335204</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* UNTESTED CODE */
data want;
    set have;
    length final_race $ 12;
    sum_races=sum(of race_whte--race_other);
    if sum_races&amp;gt;1 then final_race='multiracial';
    else if sum_races=0 then final_race='unknown';
    else do;
         if race_white=1 then race='white';
         /* You type the rest, I'm lazy */
     end;
    drop sum_races;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 05 Dec 2022 19:10:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-array-to-loop-through-all-possible-races/m-p/847878#M335204</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-12-05T19:10:08Z</dc:date>
    </item>
    <item>
      <title>Re: Using array to loop through all possible races</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-array-to-loop-through-all-possible-races/m-p/847879#M335205</link>
      <description>&lt;P&gt;Alternative (UNTESTED)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    length final_race $ 12;
    array race race_white--race_other;
    sum_races=sum(of race_white--race_other);
    if sum_races&amp;gt;1 then final_race='multiracial';
    else if sum_races=0 then final_race='unknown';
    else do i=1 to dim(race);
         if race(i)=1 then race=scan(vname(race(i)),2,'_');
     end;
    drop sum_races;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 05 Dec 2022 19:09:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-array-to-loop-through-all-possible-races/m-p/847879#M335205</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-12-05T19:09:40Z</dc:date>
    </item>
    <item>
      <title>Re: Using array to loop through all possible races</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-array-to-loop-through-all-possible-races/m-p/847881#M335206</link>
      <description>&lt;P&gt;Seems simple as long as the variable names actually match the values you want calculate.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input patient_id 
        race_white race_black race_asian race_am_indian race_pac_islander race_other race_unk
        want :$20.
  ;
cards;
1 1 0 0 0 0 0 0 white
2 1 1 0 0 0 0 0 multiracial
3 0 0 0 0 0 0 0 unknown
4 0 0 1 0 0 0 0 asian
;

data want;
  set have ;
  length final_race $20;
  array race race_: ;
  select (sum(of race[*]));
    when (.,0) final_race='unknown';
    when (1) final_race=substr(vname(race[ whichn(1,of race[*]) ]),6);
    otherwise final_race='multiracial';
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1670267380555.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/78047iF0371DF09A7930A1/image-size/large?v=v2&amp;amp;px=999" role="button" title="Tom_0-1670267380555.png" alt="Tom_0-1670267380555.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Dec 2022 19:12:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-array-to-loop-through-all-possible-races/m-p/847881#M335206</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-12-05T19:12:29Z</dc:date>
    </item>
  </channel>
</rss>

