<?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: create a variable based on values across multiple columns in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/create-a-variable-based-on-values-across-multiple-columns/m-p/584041#M166297</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
input id ind01 ind02 ind03 ind04 ind05 ind06;
array ind ind01-ind06;
zero=0;
four=0;
do i=1 to dim(ind);
zero=zero+(ind(i)=0);
four=four+(ind(i)=4);
end;
if zero+four=6 then group='A';
else if zero+four=0 then group='B';
else group='C';
drop i;
datalines;
1 0 0 0 0 4 0
2 0 0 1 0 3 0 
3 4 4 4 4 4 4
4 1 2 3 2 2 2
5 1 3 0 0 2 0
6 1 2 3 4 2 2
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 26 Aug 2019 19:21:32 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2019-08-26T19:21:32Z</dc:date>
    <item>
      <title>create a variable based on values across multiple columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-a-variable-based-on-values-across-multiple-columns/m-p/584032#M166295</link>
      <description>&lt;P&gt;My data looks like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data dat;
   input id ind01 ind02 ind03 ind04 ind05 ind06;
   datalines;
   1 0 0 0 0 4 0
   2 0 0 1 0 3 0 
   3 4 4 4 4 4 4
   4 1 2 3 2 2 2
   5 1 3 0 0 2 0 
   6 1 2 3 4 2 2
   ;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I want to create a variable to stratify the rows into three groups:&amp;nbsp;&lt;/P&gt;&lt;P&gt;group A: have either 0 or 4 for all variables ind01-ind06;&amp;nbsp;&lt;/P&gt;&lt;P&gt;group B: have any of 1 or 2 or 3, for all variables in01-ind06;&lt;/P&gt;&lt;P&gt;group C: change from (0 or 4) to (1 or 2 or 3) (or vice versa) for all variables ind01-ind06;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The ideal dataset looks like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   input id ind01 ind02 ind03 ind04 ind05 ind06 type $;
   datalines;
   1 0 0 0 0 4 0 A
   2 0 0 1 0 3 0 C
   3 4 4 4 4 4 4 A
   4 1 2 3 2 2 2 B
   5 1 3 0 0 2 0 C
   6 1 2 3 4 2 2 C
   ;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I am not sure how to create the variable since it needs tracking changes across multiple columns. Any suggestions? Thanks!!&lt;/P&gt;</description>
      <pubDate>Mon, 26 Aug 2019 19:04:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-a-variable-based-on-values-across-multiple-columns/m-p/584032#M166295</guid>
      <dc:creator>panda</dc:creator>
      <dc:date>2019-08-26T19:04:03Z</dc:date>
    </item>
    <item>
      <title>Re: create a variable based on values across multiple columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-a-variable-based-on-values-across-multiple-columns/m-p/584035#M166296</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;

data dat;
   input id ind01 ind02 ind03 ind04 ind05 ind06;
   datalines;
   1 0 0 0 0 4 0
   2 0 0 1 0 3 0 
   3 4 4 4 4 4 4
   4 1 2 3 2 2 2
   5 1 3 0 0 2 0 
   6 1 2 3 4 2 2
   ;
run;
/*Not sure of the group=C*/
data want;
set dat;
array t ind:;
if countc(cats(of t(*)),'04')=dim(t) then group='A';
else if countc(cats(of t(*)),'123')=dim(t) then group='B';
else if countc(cats(of t(*)),'04123')=dim(t) then group='C';
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 26 Aug 2019 19:13:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-a-variable-based-on-values-across-multiple-columns/m-p/584035#M166296</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-08-26T19:13:35Z</dc:date>
    </item>
    <item>
      <title>Re: create a variable based on values across multiple columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-a-variable-based-on-values-across-multiple-columns/m-p/584041#M166297</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
input id ind01 ind02 ind03 ind04 ind05 ind06;
array ind ind01-ind06;
zero=0;
four=0;
do i=1 to dim(ind);
zero=zero+(ind(i)=0);
four=four+(ind(i)=4);
end;
if zero+four=6 then group='A';
else if zero+four=0 then group='B';
else group='C';
drop i;
datalines;
1 0 0 0 0 4 0
2 0 0 1 0 3 0 
3 4 4 4 4 4 4
4 1 2 3 2 2 2
5 1 3 0 0 2 0
6 1 2 3 4 2 2
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 26 Aug 2019 19:21:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-a-variable-based-on-values-across-multiple-columns/m-p/584041#M166297</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-08-26T19:21:32Z</dc:date>
    </item>
  </channel>
</rss>

