<?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 Set, if and output statements in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Set-if-and-output-statements/m-p/242262#M44953</link>
    <description>&lt;P&gt;Hello, I just wanted to make sure I'm understanding this correctly (because it seems 30 mins ago, my understanding was incorrect).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;libname company 'SAS-data-library';
data hware inter soft;
set company.prices (keep = producttype price);
if price le 5.00;
if producttype = 'HARDWARE' then output HWARE;
else if producttype = 'NETWORK' then output INTER;
else if producttype = 'SOFTWARE' then output SOFT;
run;&lt;/PRE&gt;&lt;P&gt;So in the above piece of code, the if statements are linked to the set&amp;nbsp;statement, right? As in an observation is only being inputted into hware from the company.prices dataset, if and only if it meets the criteria of producttype = "HARDWARE" and the price is less than $5.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just as a side not, previously I was thinking that the set and if statements were not linked and that the whole company.prices dataset was going into the hware, inter and soft.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
    <pubDate>Thu, 07 Jan 2016 19:06:25 GMT</pubDate>
    <dc:creator>Durlov</dc:creator>
    <dc:date>2016-01-07T19:06:25Z</dc:date>
    <item>
      <title>Set, if and output statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Set-if-and-output-statements/m-p/242262#M44953</link>
      <description>&lt;P&gt;Hello, I just wanted to make sure I'm understanding this correctly (because it seems 30 mins ago, my understanding was incorrect).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;libname company 'SAS-data-library';
data hware inter soft;
set company.prices (keep = producttype price);
if price le 5.00;
if producttype = 'HARDWARE' then output HWARE;
else if producttype = 'NETWORK' then output INTER;
else if producttype = 'SOFTWARE' then output SOFT;
run;&lt;/PRE&gt;&lt;P&gt;So in the above piece of code, the if statements are linked to the set&amp;nbsp;statement, right? As in an observation is only being inputted into hware from the company.prices dataset, if and only if it meets the criteria of producttype = "HARDWARE" and the price is less than $5.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just as a side not, previously I was thinking that the set and if statements were not linked and that the whole company.prices dataset was going into the hware, inter and soft.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jan 2016 19:06:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Set-if-and-output-statements/m-p/242262#M44953</guid>
      <dc:creator>Durlov</dc:creator>
      <dc:date>2016-01-07T19:06:25Z</dc:date>
    </item>
    <item>
      <title>Re: Set, if and output statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Set-if-and-output-statements/m-p/242266#M44954</link>
      <description>&lt;P&gt;Yes, seems you are on the right track.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Read more here&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://support.sas.com/documentation/cdl/en/basess/58133/HTML/default/viewer.htm#a001343763.htm" target="_self"&gt;Conditionally Writing Observations to One or More SAS Data Sets&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jan 2016 19:19:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Set-if-and-output-statements/m-p/242266#M44954</guid>
      <dc:creator>mohamed_zaki</dc:creator>
      <dc:date>2016-01-07T19:19:00Z</dc:date>
    </item>
    <item>
      <title>Re: Set, if and output statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Set-if-and-output-statements/m-p/242267#M44955</link>
      <description>&lt;P&gt;It seems like you will get the desired outputs.&amp;nbsp; One thing to keep in mind is that an if statement reads in the entire dataset.&amp;nbsp; It would be advantageous to change 'if price le 5.00' to 'where price le 5.00'.&amp;nbsp; That way when you get to the if/then output statements you are reading a subset, not the entire dataset over again.&amp;nbsp; Along that same line of thought.&amp;nbsp; If you know that one output is going to be bigger than the rest you should start with that one and work incrementally towards the smallest output.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jan 2016 19:22:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Set-if-and-output-statements/m-p/242267#M44955</guid>
      <dc:creator>Steelers_In_DC</dc:creator>
      <dc:date>2016-01-07T19:22:48Z</dc:date>
    </item>
    <item>
      <title>Re: Set, if and output statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Set-if-and-output-statements/m-p/242270#M44957</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;the if statements are linked to the set&amp;nbsp;statement, right? As in an observation is only being inputted into hware from the company.prices dataset, if and only if it meets the criteria of producttype = "HARDWARE" and the price is less than $5.&amp;nbsp;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I don't think that's the quite the correct understanding. The IF statement controls what is retained into the dataset, but all observations from the SET table are brought into the data step&amp;nbsp;and then filtered and written to the requested data sets. You are correct in that not all records are automatically copied to the data subsets such as HWARE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There's the data step and then the output data sets -&amp;gt; different ideas. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;An alternative&amp;nbsp;is the WHERE statement that prevents records from being brought into the dataset in the first place. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jan 2016 19:31:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Set-if-and-output-statements/m-p/242270#M44957</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-01-07T19:31:46Z</dc:date>
    </item>
    <item>
      <title>Re: Set, if and output statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Set-if-and-output-statements/m-p/242347#M44987</link>
      <description>&lt;P&gt;You can of course update your code slighty, this datastep will read only 3 observations from the source rather than the full 5 records, so saves some reading time. &amp;nbsp;Also the other part of the where restricts to only those categories your interested in. &amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data prices;
  length producttype $20;
  input producttype $ price;
datalines;
HARDWARE 3.23
HARDWARE 7.00
NETWORK 3.43
SOFTWARE 2.22
OTHER 10.00
;
run;

data hware inter soft;
  set prices (keep=producttype price where=(price le 5.00 and producttype in ("HARDWARE","NETWORK","SOFTWARE")));
  select(producttype);
    when("HARDWARE") output hware;
    when("NETWORK") output inter;
    otherwise output soft;
  end;
run;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jan 2016 10:30:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Set-if-and-output-statements/m-p/242347#M44987</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-01-08T10:30:26Z</dc:date>
    </item>
  </channel>
</rss>

