<?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/Then statement problems in SAS Studio</title>
    <link>https://communities.sas.com/t5/SAS-Studio/If-Then-statement-problems/m-p/418345#M4123</link>
    <description>&lt;P&gt;Thank you! I'll keep that in mind.&amp;nbsp; I'm learning! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 05 Dec 2017 01:22:41 GMT</pubDate>
    <dc:creator>kmh</dc:creator>
    <dc:date>2017-12-05T01:22:41Z</dc:date>
    <item>
      <title>If/Then statement problems</title>
      <link>https://communities.sas.com/t5/SAS-Studio/If-Then-statement-problems/m-p/418047#M4111</link>
      <description>&lt;P&gt;Hello.&amp;nbsp; I'm having some basic problems. First, when trying to create a new variable with if then statements I kept getting the error code 180 "&lt;SPAN&gt;Statement is not valid or it is used out of proper order".&amp;nbsp; I finally figured out that when I used the code below I was able to get the if then statements&amp;nbsp;to work.&amp;nbsp; But I'm finding that I have to include the data step with every variable I want to create.&amp;nbsp; Now, when I try to create a table with two variables I get an error that one of the variables&amp;nbsp;cannot be found.&amp;nbsp; I'm not really sure why the if/then statements wouldn't work at first and why I have to now include the data step every time.&amp;nbsp; Any help would be appreciated for this frustrated novice &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp; &amp;nbsp;Thank you!&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;data a;&lt;BR /&gt;set edat.els0212byf3pststu_;&lt;BR /&gt;&lt;BR /&gt;latino=.;&lt;BR /&gt;if bys15=1 then latino=1; *hispanic;&lt;BR /&gt;if bys15=0 then latino=0; *non-hispanic;&lt;BR /&gt;if bys15 in (-1,-2,-4,-6,-8,-9) then latino=.;&lt;BR /&gt;else if latino=. then delete;&lt;BR /&gt;run; &lt;BR /&gt;&lt;BR /&gt;proc freq data=a;&lt;BR /&gt;tables latino;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data a;&lt;BR /&gt;set edat.els0212byf3pststu_;&lt;BR /&gt;male=.;&lt;BR /&gt;if bys14=1 then male=1; *male;&lt;BR /&gt;if bys14=2 then male=0; *female;&lt;BR /&gt;if bys14 in (-2,-4,-8,-9) then male=.;&lt;BR /&gt;else if male=. then delete;&lt;BR /&gt;run; &lt;BR /&gt;&lt;BR /&gt;proc surveyfreq data=a;&lt;BR /&gt;tables latino*male;&lt;BR /&gt;run;&lt;BR /&gt; &lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 03 Dec 2017 22:40:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/If-Then-statement-problems/m-p/418047#M4111</guid>
      <dc:creator>kmh</dc:creator>
      <dc:date>2017-12-03T22:40:29Z</dc:date>
    </item>
    <item>
      <title>Re: If/Then statement problems</title>
      <link>https://communities.sas.com/t5/SAS-Studio/If-Then-statement-problems/m-p/418048#M4112</link>
      <description>&lt;P&gt;first off, since your conditions are mutually exclusive, I would use else if and not if in repetition to check every if.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data a;&lt;BR /&gt;set edat.els0212byf3pststu_;&lt;BR /&gt;&lt;BR /&gt;latino=.;&lt;STRONG&gt;/*not needed, coz new variable is anyway initialized to missing*/&lt;/STRONG&gt;&lt;BR /&gt;if bys15=1 then latino=1; *hispanic;&lt;BR /&gt;&lt;STRONG&gt;else&lt;/STRONG&gt; if bys15=0 then latino=0; *non-hispanic;&lt;BR /&gt;&lt;STRONG&gt;else &lt;/STRONG&gt;if bys15 in (-1,-2,-4,-6,-8,-9) then latino=.;&lt;BR /&gt;&lt;STRIKE&gt;/*else*/&lt;/STRIKE&gt; if latino=. then delete;&lt;BR /&gt;run; &lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;&lt;PRE&gt;data a;&lt;BR /&gt;set edat.els0212byf3pststu_;&lt;BR /&gt;male=.;&lt;STRONG&gt;/*not needed, coz new variable is anyway initialized to missing*/&lt;/STRONG&gt;&lt;BR /&gt;if bys14=1 then male=1; *male;&lt;BR /&gt;&lt;STRONG&gt;else&lt;/STRONG&gt; if bys14=2 then male=0; *female;&lt;BR /&gt;&lt;STRONG&gt;else&lt;/STRONG&gt; if bys14 in (-2,-4,-8,-9) then male=.;&lt;BR /&gt;/*&lt;STRIKE&gt;else&lt;/STRIKE&gt; */if male=. then delete;&lt;BR /&gt;run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Combine into one step:&lt;/P&gt;&lt;PRE&gt;data a;&lt;BR /&gt;set edat.els0212byf3pststu_;&lt;/PRE&gt;&lt;PRE&gt;latino=.;&lt;STRONG&gt;/*not needed, coz new variable is anyway initialized to missing*/&lt;/STRONG&gt;&lt;BR /&gt;if bys15=1 then latino=1; *hispanic;&lt;BR /&gt;&lt;STRONG&gt;else&lt;/STRONG&gt; if bys15=0 then latino=0; *non-hispanic;&lt;BR /&gt;&lt;STRONG&gt;else &lt;/STRONG&gt;if bys15 in (-1,-2,-4,-6,-8,-9) then latino=.;&lt;BR /&gt;&lt;STRIKE&gt;/*else*/&lt;/STRIKE&gt; if latino=. then delete;&lt;/PRE&gt;&lt;PRE&gt;if bys14=1 then male=1; *male;&lt;BR /&gt;&lt;STRONG&gt;else&lt;/STRONG&gt; if bys14=2 then male=0; *female;&lt;BR /&gt;&lt;STRONG&gt;else&lt;/STRONG&gt; if bys14 in (-2,-4,-8,-9) then male=.;&lt;BR /&gt;/*&lt;STRIKE&gt;else&lt;/STRIKE&gt; */if male=. then delete;&lt;BR /&gt;run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 03 Dec 2017 23:02:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/If-Then-statement-problems/m-p/418048#M4112</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2017-12-03T23:02:23Z</dc:date>
    </item>
    <item>
      <title>Re: If/Then statement problems</title>
      <link>https://communities.sas.com/t5/SAS-Studio/If-Then-statement-problems/m-p/418054#M4113</link>
      <description>&lt;P&gt;You need to appreciate that your steps run in order.&amp;nbsp; One DATA or PROC step runs, then the next one, then the next one, etc.&amp;nbsp; That will explain part of the mystery.&amp;nbsp; But you could certainly create both variables in a single step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data a;&lt;BR /&gt;set edat.els0212byf3pststu_;&lt;BR /&gt;if bys15=1 then latino=1; *hispanic;&lt;BR /&gt;if bys15=0 then latino=0; *non-hispanic;&lt;BR /&gt;if bys14=1 then male=1; *male;&lt;BR /&gt;if bys14=2 then male=0; *female;&lt;BR /&gt;run; &lt;BR /&gt;proc freq data=a;&lt;BR /&gt;tables latino;&lt;BR /&gt;where latino &amp;gt; .;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc surveyfreq data=a;&lt;BR /&gt;tables latino*male;&lt;BR /&gt;where latino &amp;gt; . and male &amp;gt; .;&lt;BR /&gt;run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You don't absolutely require the WHERE statements ... it's only a matter of whether you want missing values to be counted by PROC FREQ.&amp;nbsp; Try it both ways (with and without WHERE statements) and see what you prefer.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Dec 2017 01:09:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/If-Then-statement-problems/m-p/418054#M4113</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-12-04T01:09:25Z</dc:date>
    </item>
    <item>
      <title>Re: If/Then statement problems</title>
      <link>https://communities.sas.com/t5/SAS-Studio/If-Then-statement-problems/m-p/418055#M4114</link>
      <description>&lt;P&gt;Why would you expect that the second version of dataset A would also include the variables from the version of A that you deleted by making another dataset with the same name?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Either create both variables in the same data step.&amp;nbsp; Or tell the second data step to use the output of the first data step as the input instead of going back to the source data.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Dec 2017 01:17:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/If-Then-statement-problems/m-p/418055#M4114</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-12-04T01:17:41Z</dc:date>
    </item>
    <item>
      <title>Re: If/Then statement problems</title>
      <link>https://communities.sas.com/t5/SAS-Studio/If-Then-statement-problems/m-p/418077#M4119</link>
      <description>&lt;P&gt;Don't think so complicated. Steps can be combined, so this should do it:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
set edat.els0212byf3pststu_;
select (bys15);
  when (1) latino = 1; *hispanic;
  when (0) latino = 0; *non-hispanic;
  otherwise delete;
end;
select (bys14);
  when (1) male = 1; *male;
  when (2) male = 0; *female;
  otherwise delete;
end;
run; 

proc freq data=a;
tables latino;
tables latino*male;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note the use of select() (the SAS version of a case statement) instead of the if-then-else chains.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Dec 2017 07:32:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/If-Then-statement-problems/m-p/418077#M4119</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-12-04T07:32:26Z</dc:date>
    </item>
    <item>
      <title>Re: If/Then statement problems</title>
      <link>https://communities.sas.com/t5/SAS-Studio/If-Then-statement-problems/m-p/418343#M4121</link>
      <description>thank you very much!&lt;BR /&gt;</description>
      <pubDate>Tue, 05 Dec 2017 01:19:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/If-Then-statement-problems/m-p/418343#M4121</guid>
      <dc:creator>kmh</dc:creator>
      <dc:date>2017-12-05T01:19:33Z</dc:date>
    </item>
    <item>
      <title>Re: If/Then statement problems</title>
      <link>https://communities.sas.com/t5/SAS-Studio/If-Then-statement-problems/m-p/418344#M4122</link>
      <description>&lt;P&gt;Thank you! This worked perfectly!&lt;/P&gt;</description>
      <pubDate>Tue, 05 Dec 2017 01:20:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/If-Then-statement-problems/m-p/418344#M4122</guid>
      <dc:creator>kmh</dc:creator>
      <dc:date>2017-12-05T01:20:14Z</dc:date>
    </item>
    <item>
      <title>Re: If/Then statement problems</title>
      <link>https://communities.sas.com/t5/SAS-Studio/If-Then-statement-problems/m-p/418345#M4123</link>
      <description>&lt;P&gt;Thank you! I'll keep that in mind.&amp;nbsp; I'm learning! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Dec 2017 01:22:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/If-Then-statement-problems/m-p/418345#M4123</guid>
      <dc:creator>kmh</dc:creator>
      <dc:date>2017-12-05T01:22:41Z</dc:date>
    </item>
    <item>
      <title>Re: If/Then statement problems</title>
      <link>https://communities.sas.com/t5/SAS-Studio/If-Then-statement-problems/m-p/418346#M4124</link>
      <description>&lt;P&gt;Thank you.&amp;nbsp; You say "tell the second data step to use the output of the first data step as the input instead of going back to the source data.". How exactly would I do that?&amp;nbsp;&lt;/P&gt;&lt;DIV class="lia-quilt-row lia-quilt-row-forum-message-footer"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Tue, 05 Dec 2017 01:24:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/If-Then-statement-problems/m-p/418346#M4124</guid>
      <dc:creator>kmh</dc:creator>
      <dc:date>2017-12-05T01:24:27Z</dc:date>
    </item>
    <item>
      <title>Re: If/Then statement problems</title>
      <link>https://communities.sas.com/t5/SAS-Studio/If-Then-statement-problems/m-p/418357#M4126</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/70891"&gt;@kmh&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Thank you.&amp;nbsp; You say "tell the second data step to use the output of the first data step as the input instead of going back to the source data.". How exactly would I do that?&amp;nbsp;&lt;/P&gt;
&lt;DIV class="lia-quilt-row lia-quilt-row-forum-message-footer"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This step will create a dataset called STEP1 from a dataset call OLD.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data step1;
  set old;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you then want to use that data and make more calculations then use as the data to be read.&amp;nbsp; So you could create STEP2 from STEP1 with a data step like this.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data step2;
  set step1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 05 Dec 2017 03:00:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/If-Then-statement-problems/m-p/418357#M4126</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-12-05T03:00:10Z</dc:date>
    </item>
  </channel>
</rss>

