<?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: Cannot recode using IF THEN ELSE in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Cannot-recode-using-IF-THEN-ELSE/m-p/565286#M158689</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/245291"&gt;@SSin&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I am trying to recode a character variable "Gender" with responses Male, Female and NA.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I used&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data =  WORK.IMPORT2; &lt;BR /&gt;&lt;BR /&gt;if 'Gender' = 'Male'   or  'Gender' = 'Female' 'Gender' = 'NA' ;&lt;BR /&gt;if 'Gender' = 'Male' then male= 1; else if 'Gender' = 'Female' 'NA' then male =0;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;and&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;If 'Gender' = 'Male' then male =1; else male=0;&lt;BR /&gt;If 'Gender' = 'Female' then female =1; else female=0; &lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;
&lt;P&gt;Both of these are not working and giving me same error message "&lt;SPAN&gt;Statement is not valid or it is used out of proper order"&lt;/SPAN&gt;. Could you please help me how to recode? I attached SAS file.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Many thanks!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;In none of the code above do you reference a Variable that might contain values of 'Male' or 'Female'. Variables are &lt;STRONG&gt;not&lt;/STRONG&gt; placed in quotes when you want to examine or modify the values of the variable. Actually there are very few times a variable name should appear in quotes generally.&lt;/P&gt;</description>
    <pubDate>Tue, 11 Jun 2019 15:09:17 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2019-06-11T15:09:17Z</dc:date>
    <item>
      <title>Cannot recode using IF THEN ELSE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cannot-recode-using-IF-THEN-ELSE/m-p/565156#M158629</link>
      <description>&lt;P&gt;I am trying to recode a character variable "Gender" with responses Male, Female and NA.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I used&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data =  WORK.IMPORT2; &lt;BR /&gt;&lt;BR /&gt;if 'Gender' = 'Male'   or  'Gender' = 'Female' 'Gender' = 'NA' ;&lt;BR /&gt;if 'Gender' = 'Male' then male= 1; else if 'Gender' = 'Female' 'NA' then male =0;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;and&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;If 'Gender' = 'Male' then male =1; else male=0;&lt;BR /&gt;If 'Gender' = 'Female' then female =1; else female=0; &lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;&lt;P&gt;Both of these are not working and giving me same error message "&lt;SPAN&gt;Statement is not valid or it is used out of proper order"&lt;/SPAN&gt;. Could you please help me how to recode? I attached SAS file.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jun 2019 09:29:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cannot-recode-using-IF-THEN-ELSE/m-p/565156#M158629</guid>
      <dc:creator>SSin</dc:creator>
      <dc:date>2019-06-11T09:29:36Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot recode using IF THEN ELSE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cannot-recode-using-IF-THEN-ELSE/m-p/565159#M158632</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The correct syntax for a data step is :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data &amp;lt;output_dataset_name&amp;gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set &amp;lt;input_dataset_name&amp;gt;;&lt;/P&gt;
&lt;P&gt;[...]&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also you are testing the equality of strings 'Gender' and 'Male'/'Female' so your tests will always be false.&lt;/P&gt;
&lt;P&gt;I think you mean the Gender variable so you have to drop the quotes :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if Gender='Male' then ...&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jun 2019 09:37:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cannot-recode-using-IF-THEN-ELSE/m-p/565159#M158632</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2019-06-11T09:37:39Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot recode using IF THEN ELSE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cannot-recode-using-IF-THEN-ELSE/m-p/565160#M158633</link>
      <description>&lt;P&gt;Don't overcomplicate it, use a select() block:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input gender $;
datalines;
male
female
NA
;

data want;
set have;
select (gender);
  when ('male') do;
    male = 1;
    female = 0;
  end;
  when ('female') do;
    male = 0;
    female = 1;
  end;
  when ('NA') do;
    male = 0;
    female = 0;
  end;
end;
run;

proc print data=want noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;gender    male    female

male        1        0  
female      0        1  
NA          0        0  
&lt;/PRE&gt;</description>
      <pubDate>Tue, 11 Jun 2019 09:37:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cannot-recode-using-IF-THEN-ELSE/m-p/565160#M158633</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-06-11T09:37:40Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot recode using IF THEN ELSE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cannot-recode-using-IF-THEN-ELSE/m-p/565286#M158689</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/245291"&gt;@SSin&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I am trying to recode a character variable "Gender" with responses Male, Female and NA.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I used&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data =  WORK.IMPORT2; &lt;BR /&gt;&lt;BR /&gt;if 'Gender' = 'Male'   or  'Gender' = 'Female' 'Gender' = 'NA' ;&lt;BR /&gt;if 'Gender' = 'Male' then male= 1; else if 'Gender' = 'Female' 'NA' then male =0;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;and&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;If 'Gender' = 'Male' then male =1; else male=0;&lt;BR /&gt;If 'Gender' = 'Female' then female =1; else female=0; &lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;
&lt;P&gt;Both of these are not working and giving me same error message "&lt;SPAN&gt;Statement is not valid or it is used out of proper order"&lt;/SPAN&gt;. Could you please help me how to recode? I attached SAS file.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Many thanks!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;In none of the code above do you reference a Variable that might contain values of 'Male' or 'Female'. Variables are &lt;STRONG&gt;not&lt;/STRONG&gt; placed in quotes when you want to examine or modify the values of the variable. Actually there are very few times a variable name should appear in quotes generally.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jun 2019 15:09:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cannot-recode-using-IF-THEN-ELSE/m-p/565286#M158689</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-06-11T15:09:17Z</dc:date>
    </item>
  </channel>
</rss>

