<?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 number of months of exposition-IF else in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/number-of-months-of-exposition-IF-else/m-p/623541#M183591</link>
    <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;In following row data for each customer there is information about number of months that he was exposed to illness.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is the way to write this code in a shorter and more useful way.&lt;/P&gt;
&lt;P&gt;Also in the real data maximum number of months of exposition is 18 (and not 6).&lt;/P&gt;
&lt;P&gt;I would like to know how to write a more general code that work also for 18 months.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
Data Rawdata;
Input ID No_Mon_expose;
cards;
1 6
2 3
3 3
4 4
5 2
6 1
7 6
8 3
9 2
10 6
;
run;


Data wanted;
set Rawdata;
if No_Mon_expose=6 then do;
Ind_Expose_Mon1=1;
Ind_Expose_Mon2=1;
Ind_Expose_Mon3=1;
Ind_Expose_Mon4=1;
Ind_Expose_Mon5=1;
Ind_Expose_Mon6=1;
end;
else if No_Mon_expose=5 then do;
Ind_Expose_Mon1=1;
Ind_Expose_Mon2=1;
Ind_Expose_Mon3=1;
Ind_Expose_Mon4=1;
Ind_Expose_Mon5=1;
Ind_Expose_Mon6=0;
end;
else if No_Mon_expose=4 then do;
Ind_Expose_Mon1=1;
Ind_Expose_Mon2=1;
Ind_Expose_Mon3=1;
Ind_Expose_Mon4=1;
Ind_Expose_Mon5=0;
Ind_Expose_Mon6=0;
end;
else if No_Mon_expose=3 then do;
Ind_Expose_Mon1=1;
Ind_Expose_Mon2=1;
Ind_Expose_Mon3=1;
Ind_Expose_Mon4=0;
Ind_Expose_Mon5=0;
Ind_Expose_Mon6=0;
end;
else if No_Mon_expose=2 then do;
Ind_Expose_Mon1=1;
Ind_Expose_Mon2=1;
Ind_Expose_Mon3=0;
Ind_Expose_Mon4=0;
Ind_Expose_Mon5=0;
Ind_Expose_Mon6=0;
end;
else if No_Mon_expose=1 then do;
Ind_Expose_Mon1=1;
Ind_Expose_Mon2=0;
Ind_Expose_Mon3=0;
Ind_Expose_Mon4=0;
Ind_Expose_Mon5=0;
Ind_Expose_Mon6=0;
end;
Run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 10 Feb 2020 11:02:23 GMT</pubDate>
    <dc:creator>Ronein</dc:creator>
    <dc:date>2020-02-10T11:02:23Z</dc:date>
    <item>
      <title>number of months of exposition-IF else</title>
      <link>https://communities.sas.com/t5/SAS-Programming/number-of-months-of-exposition-IF-else/m-p/623541#M183591</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;In following row data for each customer there is information about number of months that he was exposed to illness.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is the way to write this code in a shorter and more useful way.&lt;/P&gt;
&lt;P&gt;Also in the real data maximum number of months of exposition is 18 (and not 6).&lt;/P&gt;
&lt;P&gt;I would like to know how to write a more general code that work also for 18 months.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
Data Rawdata;
Input ID No_Mon_expose;
cards;
1 6
2 3
3 3
4 4
5 2
6 1
7 6
8 3
9 2
10 6
;
run;


Data wanted;
set Rawdata;
if No_Mon_expose=6 then do;
Ind_Expose_Mon1=1;
Ind_Expose_Mon2=1;
Ind_Expose_Mon3=1;
Ind_Expose_Mon4=1;
Ind_Expose_Mon5=1;
Ind_Expose_Mon6=1;
end;
else if No_Mon_expose=5 then do;
Ind_Expose_Mon1=1;
Ind_Expose_Mon2=1;
Ind_Expose_Mon3=1;
Ind_Expose_Mon4=1;
Ind_Expose_Mon5=1;
Ind_Expose_Mon6=0;
end;
else if No_Mon_expose=4 then do;
Ind_Expose_Mon1=1;
Ind_Expose_Mon2=1;
Ind_Expose_Mon3=1;
Ind_Expose_Mon4=1;
Ind_Expose_Mon5=0;
Ind_Expose_Mon6=0;
end;
else if No_Mon_expose=3 then do;
Ind_Expose_Mon1=1;
Ind_Expose_Mon2=1;
Ind_Expose_Mon3=1;
Ind_Expose_Mon4=0;
Ind_Expose_Mon5=0;
Ind_Expose_Mon6=0;
end;
else if No_Mon_expose=2 then do;
Ind_Expose_Mon1=1;
Ind_Expose_Mon2=1;
Ind_Expose_Mon3=0;
Ind_Expose_Mon4=0;
Ind_Expose_Mon5=0;
Ind_Expose_Mon6=0;
end;
else if No_Mon_expose=1 then do;
Ind_Expose_Mon1=1;
Ind_Expose_Mon2=0;
Ind_Expose_Mon3=0;
Ind_Expose_Mon4=0;
Ind_Expose_Mon5=0;
Ind_Expose_Mon6=0;
end;
Run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Feb 2020 11:02:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/number-of-months-of-exposition-IF-else/m-p/623541#M183591</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2020-02-10T11:02:23Z</dc:date>
    </item>
    <item>
      <title>Re: number of months of exposition-IF else</title>
      <link>https://communities.sas.com/t5/SAS-Programming/number-of-months-of-exposition-IF-else/m-p/623542#M183592</link>
      <description>&lt;P&gt;one way&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set Rawdata;
    array Ind_Expose_Mon {18} (18*0);
    do _N_=1 to No_Mon_expose;
        Ind_Expose_Mon [_N_] = 1;
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 10 Feb 2020 11:16:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/number-of-months-of-exposition-IF-else/m-p/623542#M183592</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-02-10T11:16:46Z</dc:date>
    </item>
    <item>
      <title>Re: number of months of exposition-IF else</title>
      <link>https://communities.sas.com/t5/SAS-Programming/number-of-months-of-exposition-IF-else/m-p/623543#M183593</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is a way to achieve this using an array:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Rawdata_long;
	set Rawdata;
	
	array Ind_Expose_Mon (6); /* replace by 18 */

	do i=1 to dim(Ind_Expose_Mon);
		if i&amp;lt;=No_Mon_expose then Ind_Expose_Mon(i)=1;
		else Ind_Expose_Mon(i)=0;
	end;
	
	drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 10 Feb 2020 11:17:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/number-of-months-of-exposition-IF-else/m-p/623543#M183593</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-02-10T11:17:49Z</dc:date>
    </item>
    <item>
      <title>Re: number of months of exposition-IF else</title>
      <link>https://communities.sas.com/t5/SAS-Programming/number-of-months-of-exposition-IF-else/m-p/623609#M183627</link>
      <description>&lt;P&gt;very likely making a wide data set will make later steps harder, depending on how this data is to be used.&lt;/P&gt;</description>
      <pubDate>Mon, 10 Feb 2020 16:27:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/number-of-months-of-exposition-IF-else/m-p/623609#M183627</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-02-10T16:27:47Z</dc:date>
    </item>
    <item>
      <title>Re: number of months of exposition-IF else</title>
      <link>https://communities.sas.com/t5/SAS-Programming/number-of-months-of-exposition-IF-else/m-p/623617#M183630</link>
      <description>&lt;P&gt;You should be able to do this with an array.&amp;nbsp;&amp;nbsp;Take advantage of the fact that SAS evaluate boolean expressions to 0 or 1 to make setting the value easier.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data wanted;
  set Rawdata;
  array Ind_Expose_Mon [18];
  do index=1 to dim(Ind_Expose_Mon);
    Ind_Expose_Mon[index]= (index &amp;lt;= No_Mon_expose) ;
  end;
  drop index;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Whether you want to or not is a different question.&lt;/P&gt;</description>
      <pubDate>Mon, 10 Feb 2020 16:42:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/number-of-months-of-exposition-IF-else/m-p/623617#M183630</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-02-10T16:42:44Z</dc:date>
    </item>
  </channel>
</rss>

