<?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: If statement for creating new variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/If-statement-for-creating-new-variable/m-p/726567#M225842</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*name of output data set is Step2;
data Work.STEP2;

*name of input data set is Import;
set Work.IMPORT;

*Household Education is set to 1 for householdID_1 =1, else 0;
if householdID_1 = 1 then household_ED=1;
else household_ed = 0;

run; 

*check results;
proc freq data=Step2;
table HouseHold_ED*HOUSEHOLDID_1*EducationLevel / list;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If this doesn't give you what you want, please post the otuput from the PROC FREQ and show us what you want each value coded as, compared to what it's currently coded as.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;EDIT: To correct spelling issue in a variable name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/157868"&gt;@Achieng&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Dear friend,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to create a new variable.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am evaluating the education level of household members. But I have an educational level for everyone in the study.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Educationlevel (levels 1-5) In my new coding, I want educationlevel =0, bt all others equals=1 for householdID_1, Please help.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data=Work.IMPORT;set Work.IMPORT;
else if HouseholdID_1=1 the do;
else If Educationlevel="1" &amp;amp; HouseholdID_1="1" then Household_ED="0";
else If Educationlevel="2" &amp;amp; HouseholdID_1="2" then Household_ED="1";
else If Educationlevel="3" &amp;amp; HouseholdID_1="3" then Household_ED="1';
else If Educationlevel="4" &amp;amp; HouseholdID_1="4" then Household_ED="1";
If Educationlevel="5" &amp;amp; HouseholdID_1="5" then Household_ED="1";
run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 15 Mar 2021 22:46:18 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2021-03-15T22:46:18Z</dc:date>
    <item>
      <title>If statement for creating new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-statement-for-creating-new-variable/m-p/726561#M225841</link>
      <description>&lt;P&gt;Dear friend,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to create a new variable.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am evaluating the education level of household members. But I have an educational level for everyone in the study.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Educationlevel (levels 1-5) In my new coding, I want educationlevel =0, bt all others equals=1 for householdID_1, Please help.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data=Work.IMPORT;set Work.IMPORT;
else if HouseholdID_1=1 the do;
else If Educationlevel="1" &amp;amp; HouseholdID_1="1" then Household_ED="0";
else If Educationlevel="2" &amp;amp; HouseholdID_1="2" then Household_ED="1";
else If Educationlevel="3" &amp;amp; HouseholdID_1="3" then Household_ED="1';
else If Educationlevel="4" &amp;amp; HouseholdID_1="4" then Household_ED="1";
If Educationlevel="5" &amp;amp; HouseholdID_1="5" then Household_ED="1";
run; &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 15 Mar 2021 22:14:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-statement-for-creating-new-variable/m-p/726561#M225841</guid>
      <dc:creator>Achieng</dc:creator>
      <dc:date>2021-03-15T22:14:13Z</dc:date>
    </item>
    <item>
      <title>Re: If statement for creating new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-statement-for-creating-new-variable/m-p/726567#M225842</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*name of output data set is Step2;
data Work.STEP2;

*name of input data set is Import;
set Work.IMPORT;

*Household Education is set to 1 for householdID_1 =1, else 0;
if householdID_1 = 1 then household_ED=1;
else household_ed = 0;

run; 

*check results;
proc freq data=Step2;
table HouseHold_ED*HOUSEHOLDID_1*EducationLevel / list;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If this doesn't give you what you want, please post the otuput from the PROC FREQ and show us what you want each value coded as, compared to what it's currently coded as.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;EDIT: To correct spelling issue in a variable name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/157868"&gt;@Achieng&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Dear friend,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to create a new variable.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am evaluating the education level of household members. But I have an educational level for everyone in the study.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Educationlevel (levels 1-5) In my new coding, I want educationlevel =0, bt all others equals=1 for householdID_1, Please help.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data=Work.IMPORT;set Work.IMPORT;
else if HouseholdID_1=1 the do;
else If Educationlevel="1" &amp;amp; HouseholdID_1="1" then Household_ED="0";
else If Educationlevel="2" &amp;amp; HouseholdID_1="2" then Household_ED="1";
else If Educationlevel="3" &amp;amp; HouseholdID_1="3" then Household_ED="1';
else If Educationlevel="4" &amp;amp; HouseholdID_1="4" then Household_ED="1";
If Educationlevel="5" &amp;amp; HouseholdID_1="5" then Household_ED="1";
run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Mar 2021 22:46:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-statement-for-creating-new-variable/m-p/726567#M225842</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-03-15T22:46:18Z</dc:date>
    </item>
    <item>
      <title>Re: If statement for creating new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-statement-for-creating-new-variable/m-p/726569#M225843</link>
      <description>thank you very much.&lt;BR /&gt;There are no Proc freq data.&lt;BR /&gt;This is what I am getting in the logs&lt;BR /&gt;&lt;BR /&gt;NOTE: Variable househouldID_1 is uninitialized.&lt;BR /&gt;NOTE: There were 3301 observations read from the data set WORK.IMPORT.&lt;BR /&gt;NOTE: The data set WORK.STEP2 has 3301 observations and 367 variables.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 0.01 seconds&lt;BR /&gt;user cpu time 0.01 seconds&lt;BR /&gt;system cpu time 0.00 seconds&lt;BR /&gt;memory 4142.87k&lt;BR /&gt;OS Memory 39596.00k&lt;BR /&gt;Timestamp 15/03/2021 10:33:48 PM&lt;BR /&gt;Step Count 128 Switch Count 3&lt;BR /&gt;Page Faults 0&lt;BR /&gt;Page Reclaims 805&lt;BR /&gt;Page Swaps 0&lt;BR /&gt;Voluntary Context Switches 14&lt;BR /&gt;Involuntary Context Switches 0&lt;BR /&gt;Block Input Operations 0&lt;BR /&gt;Block Output Operations 22536&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 15 Mar 2021 22:37:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-statement-for-creating-new-variable/m-p/726569#M225843</guid>
      <dc:creator>Achieng</dc:creator>
      <dc:date>2021-03-15T22:37:45Z</dc:date>
    </item>
    <item>
      <title>Re: If statement for creating new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-statement-for-creating-new-variable/m-p/726574#M225844</link>
      <description>NOTE: Variable househouldID_1 is uninitialized.&lt;BR /&gt;&lt;BR /&gt;I made a typo in the code above, notice the extra u. Please fix the code by correcting the variable name, re-running it and posting the output.</description>
      <pubDate>Mon, 15 Mar 2021 22:45:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-statement-for-creating-new-variable/m-p/726574#M225844</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-03-15T22:45:33Z</dc:date>
    </item>
    <item>
      <title>Re: If statement for creating new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-statement-for-creating-new-variable/m-p/726586#M225845</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/157868"&gt;@Achieng&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Dear friend,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to create a new variable.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am evaluating the education level of household members. But I have an educational level for everyone in the study.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Educationlevel (levels 1-5) In my new coding, I want educationlevel =0, bt all others equals=1 for householdID_1, Please help.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data=Work.IMPORT;set Work.IMPORT;
else if HouseholdID_1=1 the do;
else If Educationlevel="1" &amp;amp; HouseholdID_1="1" then Household_ED="0";
else If Educationlevel="2" &amp;amp; HouseholdID_1="2" then Household_ED="1";
else If Educationlevel="3" &amp;amp; HouseholdID_1="3" then Household_ED=&lt;U&gt;&lt;STRONG&gt;&lt;FONT size="5" color="#FF0000"&gt;"1';&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/U&gt;
else If Educationlevel="4" &amp;amp; HouseholdID_1="4" then Household_ED="1";
If Educationlevel="5" &amp;amp; HouseholdID_1="5" then Household_ED="1";
run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Mismatched quote is the reason for missing values and likely warnings in the LOG (eventually).&lt;/P&gt;
&lt;P&gt;When asking why something is not behaving it is import to copy from the log the data step or procedure with all the notes and warnings. Copy the text and paste into a text box on the forum opened using the &amp;lt;/&amp;gt; icon to preserve formatting.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Mar 2021 23:12:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-statement-for-creating-new-variable/m-p/726586#M225845</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-03-15T23:12:00Z</dc:date>
    </item>
    <item>
      <title>Re: If statement for creating new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-statement-for-creating-new-variable/m-p/726587#M225846</link>
      <description>Thank you Reeza,&lt;BR /&gt;It has worked.&lt;BR /&gt;the output table is too large.&lt;BR /&gt;this part of the log&lt;BR /&gt;&lt;BR /&gt;OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;&lt;BR /&gt;72&lt;BR /&gt;73 *name of output data set is Step2;&lt;BR /&gt;74 data Work.STEP2;&lt;BR /&gt;75&lt;BR /&gt;76 *name of input data set is Import;&lt;BR /&gt;77 set Work.IMPORT;&lt;BR /&gt;78&lt;BR /&gt;79 *Household Education is set to 1 for householdID_2 =1, else 0;&lt;BR /&gt;80 if householdID_2 = 1 then household_ED=1;&lt;BR /&gt;81 else household_ed = 0;&lt;BR /&gt;82&lt;BR /&gt;83 run;&lt;BR /&gt;NOTE: There were 3301 observations read from the data set WORK.IMPORT.&lt;BR /&gt;NOTE: The data set WORK.STEP2 has 3301 observations and 366 variables.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 0.01 seconds&lt;BR /&gt;user cpu time 0.01 seconds&lt;BR /&gt;system cpu time 0.01 seconds&lt;BR /&gt;memory 4175.78k&lt;BR /&gt;OS Memory 40364.00k&lt;BR /&gt;Timestamp 15/03/2021 11:11:39 PM&lt;BR /&gt;Step Count 183 Switch Count 3&lt;BR /&gt;Page Faults 0&lt;BR /&gt;Page Reclaims 670&lt;BR /&gt;Page Swaps 0&lt;BR /&gt;Voluntary Context Switches 17&lt;BR /&gt;Involuntary Context Switches 0&lt;BR /&gt;Block Input Operations 0&lt;BR /&gt;Block Output Operations 22536&lt;BR /&gt;84&lt;BR /&gt;85 *check results;&lt;BR /&gt;86 proc freq data=Step2;&lt;BR /&gt;87 table HouseHold_ED*HOUSEHOLDID_2*EducationLevel / list;&lt;BR /&gt;88 run;&lt;BR /&gt;NOTE: There were 3301 observations read from the data set WORK.STEP2.&lt;BR /&gt;NOTE: PROCEDURE FREQ used (Total process time):&lt;BR /&gt;real time 0.02 seconds&lt;BR /&gt;user cpu time 0.02 seconds&lt;BR /&gt;system cpu time 0.01 seconds&lt;BR /&gt;memory 3560.93k&lt;BR /&gt;OS Memory 39352.00k&lt;BR /&gt;Timestamp 15/03/2021 11:11:39 PM&lt;BR /&gt;Step Count 184 Switch Count 8&lt;BR /&gt;Page Faults 0&lt;BR /&gt;Page Reclaims 534&lt;BR /&gt;Page Swaps 0&lt;BR /&gt;Voluntary Context Switches 40&lt;BR /&gt;Involuntary Context Switches 0&lt;BR /&gt;Block Input Operations 0&lt;BR /&gt;Block Output Operations 1064&lt;BR /&gt;&lt;BR /&gt;Thnak youveery very much&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 15 Mar 2021 23:16:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-statement-for-creating-new-variable/m-p/726587#M225846</guid>
      <dc:creator>Achieng</dc:creator>
      <dc:date>2021-03-15T23:16:45Z</dc:date>
    </item>
  </channel>
</rss>

