<?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: How to make this [If condition1 then result1 and output1] happen? in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/How-to-make-this-If-condition1-then-result1-and-output1-happen/m-p/515837#M3029</link>
    <description>Thank you so much. I am gonna try this. Need a clarification. What is the function of 'otherwise' here? And, don't we need 'run;' at the end?</description>
    <pubDate>Sun, 25 Nov 2018 22:32:51 GMT</pubDate>
    <dc:creator>d6k5d3</dc:creator>
    <dc:date>2018-11-25T22:32:51Z</dc:date>
    <item>
      <title>How to make this [If condition1 then result1 and output1] happen?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-make-this-If-condition1-then-result1-and-output1-happen/m-p/515818#M3019</link>
      <description>&lt;P&gt;From a dataset I need to filter one kind of value, and create a separate dataset&amp;nbsp; with that value. But before doing that I need to create a column. So what I am trying to do is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data x1;&lt;/P&gt;&lt;P&gt;set zzz;&lt;/P&gt;&lt;P&gt;if x=123 then a=1 and output x1; ===&amp;gt; I know this doesn't work.&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, my new dataset x1 will have a new column 'a' with 1 for each x=123 in each row. How can I do both in one datastep?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Much thanks.&lt;/P&gt;</description>
      <pubDate>Sun, 25 Nov 2018 19:45:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-make-this-If-condition1-then-result1-and-output1-happen/m-p/515818#M3019</guid>
      <dc:creator>d6k5d3</dc:creator>
      <dc:date>2018-11-25T19:45:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to make this [If condition1 then result1 and output1] happen?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-make-this-If-condition1-then-result1-and-output1-happen/m-p/515822#M3020</link>
      <description>&lt;P&gt;It's much simpler than you thought. There's two ways:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data z1;
set zzz;
if x = 123;
a = 1;
output;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But because you're only creating one dataset, the output statement is implied:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data z1;
set zzz;
if x = 123;
a = 1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note the if statement. It's known as a subsetting if - only when it is true are the statements after it executed.&lt;/P&gt;</description>
      <pubDate>Sun, 25 Nov 2018 20:41:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-make-this-If-condition1-then-result1-and-output1-happen/m-p/515822#M3020</guid>
      <dc:creator>LaurieF</dc:creator>
      <dc:date>2018-11-25T20:41:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to make this [If condition1 then result1 and output1] happen?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-make-this-If-condition1-then-result1-and-output1-happen/m-p/515824#M3021</link>
      <description>&lt;P&gt;this will give you all of your records and includes a variable named a that is set to the value of 1 for only records where x = 123&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data x1;
set zzz;
if x = 123 then a = 1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;this will output only if x = 123&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data x1;
set zzz;
if x = 123 then do;
a = 1;
output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 25 Nov 2018 21:17:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-make-this-If-condition1-then-result1-and-output1-happen/m-p/515824#M3021</guid>
      <dc:creator>VDD</dc:creator>
      <dc:date>2018-11-25T21:17:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to make this [If condition1 then result1 and output1] happen?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-make-this-If-condition1-then-result1-and-output1-happen/m-p/515835#M3027</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/17429"&gt;@LaurieF&lt;/a&gt;&amp;amp;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/122002"&gt;@VDD&lt;/a&gt;, I beg your pardon because I think my message has not been clear. This is what I would do, and I also looking for ways to do it using macro.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a master file. In that I have a column called 'event'. There are 10 events out of which I need 5 events. For each event I need to give a code, and generate an output having the name of the code for each event. I am aiming to do this in one datastep. So, with repetition I would code it the following way.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data code1;&lt;/P&gt;&lt;P&gt;set master;&lt;/P&gt;&lt;P&gt;if event="xxxxx" then code="code1";&lt;/P&gt;&lt;P&gt;else delete;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data code2;&lt;/P&gt;&lt;P&gt;set master;&lt;/P&gt;&lt;P&gt;if event="yyyyy" then code="code2";&lt;/P&gt;&lt;P&gt;else delete;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;... … … (I will repeat the above code 3 more times with changes where needed)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;what would be an efficient way to accomplish the above task? can I do this using macro? I think that would be fantastic.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards.&lt;/P&gt;</description>
      <pubDate>Sun, 25 Nov 2018 22:23:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-make-this-If-condition1-then-result1-and-output1-happen/m-p/515835#M3027</guid>
      <dc:creator>d6k5d3</dc:creator>
      <dc:date>2018-11-25T22:23:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to make this [If condition1 then result1 and output1] happen?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-make-this-If-condition1-then-result1-and-output1-happen/m-p/515836#M3028</link>
      <description>&lt;P&gt;Oh - that's still quite straight-forward.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data code1 code2 code3 code4 code5;
set master;
select(event);
   when('xxxxx') do;
         code = 'code1';
         output code1;
         end;
   when('yyyyy') do;
          code = 'code2';
          output code2;
          end;
   when('zzzzz') do;
          code = 'code3';
          output code3;
          end;
   when('aaaaa') do;
          code = 'code4';
          output code4;
          end;
   when('bbbbb') do;
          code = 'code5';
          output code5;
          end;
   otherwise;
   end;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Since they're all distinct or mutually exclusive conditions, a&amp;nbsp;&lt;EM&gt;select&lt;/EM&gt; statement is the way to go. And you can write them all out in one pass of your source dataset.&lt;/P&gt;</description>
      <pubDate>Sun, 25 Nov 2018 22:28:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-make-this-If-condition1-then-result1-and-output1-happen/m-p/515836#M3028</guid>
      <dc:creator>LaurieF</dc:creator>
      <dc:date>2018-11-25T22:28:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to make this [If condition1 then result1 and output1] happen?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-make-this-If-condition1-then-result1-and-output1-happen/m-p/515837#M3029</link>
      <description>Thank you so much. I am gonna try this. Need a clarification. What is the function of 'otherwise' here? And, don't we need 'run;' at the end?</description>
      <pubDate>Sun, 25 Nov 2018 22:32:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-make-this-If-condition1-then-result1-and-output1-happen/m-p/515837#M3029</guid>
      <dc:creator>d6k5d3</dc:creator>
      <dc:date>2018-11-25T22:32:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to make this [If condition1 then result1 and output1] happen?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-make-this-If-condition1-then-result1-and-output1-happen/m-p/515838#M3030</link>
      <description>&lt;P&gt;Technically, the&amp;nbsp;&lt;U&gt;&lt;/U&gt;&lt;EM&gt;otherwise&lt;/EM&gt; isn't needed. I always include it, because it saves a potential warning/error message.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And yes, put a&amp;nbsp;&lt;EM&gt;run&lt;/EM&gt; to make it work!&lt;/P&gt;</description>
      <pubDate>Sun, 25 Nov 2018 22:34:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-make-this-If-condition1-then-result1-and-output1-happen/m-p/515838#M3030</guid>
      <dc:creator>LaurieF</dc:creator>
      <dc:date>2018-11-25T22:34:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to make this [If condition1 then result1 and output1] happen?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-make-this-If-condition1-then-result1-and-output1-happen/m-p/515840#M3031</link>
      <description>SAS was giving me an error without the 'otherwise'!&lt;BR /&gt;&lt;BR /&gt;ERROR: Unsatisfied WHEN clause and no OTHERWISE clause at line 6245 column 1&lt;BR /&gt;</description>
      <pubDate>Sun, 25 Nov 2018 22:44:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-make-this-If-condition1-then-result1-and-output1-happen/m-p/515840#M3031</guid>
      <dc:creator>d6k5d3</dc:creator>
      <dc:date>2018-11-25T22:44:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to make this [If condition1 then result1 and output1] happen?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-make-this-If-condition1-then-result1-and-output1-happen/m-p/515842#M3032</link>
      <description>&lt;P&gt;Ah, there you go then - always use&amp;nbsp;&lt;EM&gt;otherwise&lt;/EM&gt;!&lt;/P&gt;</description>
      <pubDate>Sun, 25 Nov 2018 22:44:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-make-this-If-condition1-then-result1-and-output1-happen/m-p/515842#M3032</guid>
      <dc:creator>LaurieF</dc:creator>
      <dc:date>2018-11-25T22:44:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to make this [If condition1 then result1 and output1] happen?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-make-this-If-condition1-then-result1-and-output1-happen/m-p/515848#M3033</link>
      <description>Encountered another problem! Is it possible to write multiple 'when' 'conditions'? Like:&lt;BR /&gt;&lt;BR /&gt;data code1 code2 code3 code4 code5;&lt;BR /&gt;set master;&lt;BR /&gt;select(event);&lt;BR /&gt;when('xxxxx') or when ('xyxyxy') do;&lt;BR /&gt;code = 'code1';&lt;BR /&gt;output code1;&lt;BR /&gt;end;&lt;BR /&gt;… … … …</description>
      <pubDate>Sun, 25 Nov 2018 23:12:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-make-this-If-condition1-then-result1-and-output1-happen/m-p/515848#M3033</guid>
      <dc:creator>d6k5d3</dc:creator>
      <dc:date>2018-11-25T23:12:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to make this [If condition1 then result1 and output1] happen?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-make-this-If-condition1-then-result1-and-output1-happen/m-p/515850#M3034</link>
      <description>&lt;P&gt;Much simpler:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;when('xxxxx', 'xyxyxy') do;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This is what you need:&amp;nbsp;&lt;A href="http://support.sas.com/documentation/cdl//en/lestmtsref/69738/HTML/default/viewer.htm#p09213s9jc2t99n1vx0omk2rh9ps.htm" target="_blank"&gt;Select statement&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 25 Nov 2018 23:48:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-make-this-If-condition1-then-result1-and-output1-happen/m-p/515850#M3034</guid>
      <dc:creator>LaurieF</dc:creator>
      <dc:date>2018-11-25T23:48:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to make this [If condition1 then result1 and output1] happen?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-make-this-If-condition1-then-result1-and-output1-happen/m-p/515880#M3036</link>
      <description>I am grateful to you for all your time and help! I wish I had been a little more careful when I was reading the 'when statement' earlier.</description>
      <pubDate>Mon, 26 Nov 2018 02:45:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-make-this-If-condition1-then-result1-and-output1-happen/m-p/515880#M3036</guid>
      <dc:creator>d6k5d3</dc:creator>
      <dc:date>2018-11-26T02:45:06Z</dc:date>
    </item>
  </channel>
</rss>

