<?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: generate a new combined variable by using if and then statements in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/generate-a-new-combined-variable-by-using-if-and-then-statements/m-p/623794#M19997</link>
    <description>&lt;P&gt;Your three formats are identical, so one will suffice.&lt;/P&gt;
&lt;P&gt;You can also greatly simplify your code by using an informat for the transformation, and combining all freq tables into one procedure call.&lt;/P&gt;
&lt;P&gt;Your question can be solved with the help of the countc() function, applied to a string containing all three values:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
invalue instate
  31,32,33,34,35,36 = 1
  11,12,13 = 2
  21,22,23,24,25,26 = 3
;
value outstate
  1 = "Finished"
  2 = "Natural"
  3 = "Rudimentary"
;
run;

data homework2; /* create some fake data */
input HV215 HV213 HV214;
datalines;
31 31 11
21 22 23
;

data homework2_2;
set homework2;
Roof = input(HV215,instate.);
Floor = input(HV213,instate.);
Wall = input(HV214,instate.);
format Roof Floor Wall outstate.;
flag_finished = (countc(cats(Roof,Floor,Wall),'1') &amp;gt; 1);
run;

proc freq data=work.homework2_2;
tables Wall;
tables Roof;
tables Floor;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 11 Feb 2020 09:13:18 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2020-02-11T09:13:18Z</dc:date>
    <item>
      <title>generate a new combined variable by using if and then statements</title>
      <link>https://communities.sas.com/t5/New-SAS-User/generate-a-new-combined-variable-by-using-if-and-then-statements/m-p/623780#M19995</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;I need some advice on how to generate a new combined variable by using if and then statements. I have created separate variables using the if statement, and I have also used the proc format. But after that, I need to combine the variables. I have been trying to combine those new variables, in something like "if at least two of the three materials (wall, roof, and floor) were finished", but I couldn't. Could you guide me to know how to do it?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the SAS code with the variables that I have to combine (wall, roof, and floor).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Thank you for your help&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname Assig2 "/folders/myfolders/study3";
data work.homework2;
set Assig2.homework2;
  
if  HV215 in (31,32,33,34,35,36)    then Roof= 1;
if  HV215 in (11,12,13)             then Roof= 2;
if  HV215 in (21,22,23,24,25)      then Roof= 3;
   
if  HV213 in (31,33,34,35)    then Floor= 1;
if  HV213 in (11,12)          then Floor= 2;
if  HV213 in (21,22)          then Floor= 3;

if  HV214 in (31,32,33,34,35,36)    then Wall= 1;
if  HV214 in (11,12,13)             then Wall= 2;
if  HV214 in (21,22,23,24,25,26)      then Wall= 3;
run;
proc format;
value Wall
1="Finished"
2= "Natural"
3= "Rudimentary";
run;
proc format;
value Roof
1="Finished"
2= "Natural"
3= "Rudimentary";
run;
proc format;
value Floor
1="Finished"
2= "Natural"
3= "Rudimentary";
run;
Proc freq data=work.homework2;
tables Wall;
format Wall Wall. ;
run;
Proc freq data=work.homework2;
tables Roof;
format Roof Roof. ;
run;
Proc freq data=work.homework2;
tables Floor;
format Floor Floor. ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 11 Feb 2020 07:29:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/generate-a-new-combined-variable-by-using-if-and-then-statements/m-p/623780#M19995</guid>
      <dc:creator>xoxozav_1</dc:creator>
      <dc:date>2020-02-11T07:29:45Z</dc:date>
    </item>
    <item>
      <title>Re: generate a new combined variable by using if and then statements</title>
      <link>https://communities.sas.com/t5/New-SAS-User/generate-a-new-combined-variable-by-using-if-and-then-statements/m-p/623786#M19996</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/310302"&gt;@xoxozav_1&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does this additional statement in the DATA step meet your expectations ?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if (Roof=1 and Floor=1) or (Roof=1 and Wall=1) or (Floor=1 and Wall=1) then flag_finished = 1;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 11 Feb 2020 08:44:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/generate-a-new-combined-variable-by-using-if-and-then-statements/m-p/623786#M19996</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-02-11T08:44:50Z</dc:date>
    </item>
    <item>
      <title>Re: generate a new combined variable by using if and then statements</title>
      <link>https://communities.sas.com/t5/New-SAS-User/generate-a-new-combined-variable-by-using-if-and-then-statements/m-p/623794#M19997</link>
      <description>&lt;P&gt;Your three formats are identical, so one will suffice.&lt;/P&gt;
&lt;P&gt;You can also greatly simplify your code by using an informat for the transformation, and combining all freq tables into one procedure call.&lt;/P&gt;
&lt;P&gt;Your question can be solved with the help of the countc() function, applied to a string containing all three values:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
invalue instate
  31,32,33,34,35,36 = 1
  11,12,13 = 2
  21,22,23,24,25,26 = 3
;
value outstate
  1 = "Finished"
  2 = "Natural"
  3 = "Rudimentary"
;
run;

data homework2; /* create some fake data */
input HV215 HV213 HV214;
datalines;
31 31 11
21 22 23
;

data homework2_2;
set homework2;
Roof = input(HV215,instate.);
Floor = input(HV213,instate.);
Wall = input(HV214,instate.);
format Roof Floor Wall outstate.;
flag_finished = (countc(cats(Roof,Floor,Wall),'1') &amp;gt; 1);
run;

proc freq data=work.homework2_2;
tables Wall;
tables Roof;
tables Floor;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Feb 2020 09:13:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/generate-a-new-combined-variable-by-using-if-and-then-statements/m-p/623794#M19997</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-02-11T09:13:18Z</dc:date>
    </item>
  </channel>
</rss>

