<?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 Urgent: Using several set- options in a datastep in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Urgent-Using-several-set-options-in-a-datastep/m-p/415233#M280110</link>
    <description>&lt;P&gt;Hello,&lt;BR /&gt;&lt;BR /&gt;i have a rather urgent problem which occurred to me today as i was writing a quite complex program today. I've used a dummy dataset to create the logic i needed for the program to work. But have realized it does not work on the real data due to&amp;nbsp; missing information (Gonna focus more on realistic dummydata next time).&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;The program is written in a macro where there are a lot of set statements depends on a&amp;nbsp;several if-statements and such. Therefore i can not write it as the "collect_working" is structured.&amp;nbsp; Below is an illustration of the problem:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data dummydata;&lt;BR /&gt;input flag1 flag2 flag3 val;&lt;BR /&gt;datalines;&lt;BR /&gt;1 1 1 33&lt;BR /&gt;1 0 . 44&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data collect_notworking;&lt;BR /&gt;set work.dummydata(where=(flag1 =1 and flag2=0 and flag3=1));&lt;BR /&gt;output;&lt;BR /&gt;set work.dummydata(where=(flag1 =1 and flag2=1 ));&lt;BR /&gt;output;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data collect_working;&lt;BR /&gt;set work.dummydata(where=(flag1 =1 and flag2=0 and flag3=1))&lt;BR /&gt;work.dummydata(where=(flag1 =1 and flag2=0 ));&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem that arises in collect_notworking is the first set-statement contains 0 observations. After this the datastep seems to stop and does not handle the next set-statement.&lt;BR /&gt;&lt;BR /&gt;Collect_working handles everyting in one set-statement and handles this problem.&lt;BR /&gt;&lt;BR /&gt;So my question is: Is there a way to handle 0-observation cases as in this example with multiple set-statements?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've tried to look into the exist-function and such but have not been able to successfully use it.&lt;BR /&gt;&lt;BR /&gt;Thank you on advance!&lt;/P&gt;</description>
    <pubDate>Tue, 21 Nov 2017 15:56:42 GMT</pubDate>
    <dc:creator>Shawnty</dc:creator>
    <dc:date>2017-11-21T15:56:42Z</dc:date>
    <item>
      <title>Urgent: Using several set- options in a datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Urgent-Using-several-set-options-in-a-datastep/m-p/415233#M280110</link>
      <description>&lt;P&gt;Hello,&lt;BR /&gt;&lt;BR /&gt;i have a rather urgent problem which occurred to me today as i was writing a quite complex program today. I've used a dummy dataset to create the logic i needed for the program to work. But have realized it does not work on the real data due to&amp;nbsp; missing information (Gonna focus more on realistic dummydata next time).&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;The program is written in a macro where there are a lot of set statements depends on a&amp;nbsp;several if-statements and such. Therefore i can not write it as the "collect_working" is structured.&amp;nbsp; Below is an illustration of the problem:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data dummydata;&lt;BR /&gt;input flag1 flag2 flag3 val;&lt;BR /&gt;datalines;&lt;BR /&gt;1 1 1 33&lt;BR /&gt;1 0 . 44&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data collect_notworking;&lt;BR /&gt;set work.dummydata(where=(flag1 =1 and flag2=0 and flag3=1));&lt;BR /&gt;output;&lt;BR /&gt;set work.dummydata(where=(flag1 =1 and flag2=1 ));&lt;BR /&gt;output;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data collect_working;&lt;BR /&gt;set work.dummydata(where=(flag1 =1 and flag2=0 and flag3=1))&lt;BR /&gt;work.dummydata(where=(flag1 =1 and flag2=0 ));&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem that arises in collect_notworking is the first set-statement contains 0 observations. After this the datastep seems to stop and does not handle the next set-statement.&lt;BR /&gt;&lt;BR /&gt;Collect_working handles everyting in one set-statement and handles this problem.&lt;BR /&gt;&lt;BR /&gt;So my question is: Is there a way to handle 0-observation cases as in this example with multiple set-statements?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've tried to look into the exist-function and such but have not been able to successfully use it.&lt;BR /&gt;&lt;BR /&gt;Thank you on advance!&lt;/P&gt;</description>
      <pubDate>Tue, 21 Nov 2017 15:56:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Urgent-Using-several-set-options-in-a-datastep/m-p/415233#M280110</guid>
      <dc:creator>Shawnty</dc:creator>
      <dc:date>2017-11-21T15:56:42Z</dc:date>
    </item>
    <item>
      <title>Re: Urgent: Using several set- options in a datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Urgent-Using-several-set-options-in-a-datastep/m-p/415241#M280111</link>
      <description>&lt;P&gt;What is it your actually trying to do?&amp;nbsp; If the set statement has nothing to read then the datastep ends.&amp;nbsp; This code:&lt;/P&gt;
&lt;PRE&gt;data collect_notworking;
  set work.dummydata(where=(flag1 =1 and flag2=0 and flag3=1));
  output;
  set work.dummydata(where=(flag1 =1 and flag2=1 ));
  output;
run;&lt;/PRE&gt;
&lt;P&gt;Doesn't make any sense.&amp;nbsp; If you want a dataset with all the records from the two wheres then this is the code:&lt;/P&gt;
&lt;PRE&gt;data collect_notworking;
  set work.dummydata (where=(flag1 =1 and flag2=0 and flag3=1))
        work.dummydata (where=(flag1=1 and flag2=1));
run;&lt;/PRE&gt;
&lt;P&gt;Or in fact you could just do:&lt;/P&gt;
&lt;PRE&gt;data collect_notworking;
  set work.dummydata (where=((flag1 =1 and flag2=0 and flag3=1) or (flag1=1 and flag2=1)));
run;&lt;/PRE&gt;
&lt;P&gt;This "&lt;SPAN&gt;The program is written in a macro where there are a lot of set statements depends on a&amp;nbsp;several if-statements and such. Therefore i can not write it as the "collect_working" is structured.&amp;nbsp; Below is an illustration of the problem:" - just sounds like your trying to fight the SAS system, and read/write each line yourself - which isn't going to work.&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Nov 2017 16:20:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Urgent-Using-several-set-options-in-a-datastep/m-p/415241#M280111</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-11-21T16:20:58Z</dc:date>
    </item>
    <item>
      <title>Re: Urgent: Using several set- options in a datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Urgent-Using-several-set-options-in-a-datastep/m-p/415247#M280112</link>
      <description>&lt;P&gt;Assuming you really must do it that way, here is a workaround.&amp;nbsp; Other similar workarounds would be possible, if you have some requirements about the order of the observations in the final data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;if end1=0 then do;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;set work.dummydata(where=(flag1 =1 and flag2=0 and flag3=1)) end=end1;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;output;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;if end2=0 then do;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;set work.dummydata(where=(flag1 =1 and flag2=1 )) end=end2;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;output;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;if end1 and end2 then stop;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But as both you and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;&amp;nbsp;suggested, there are plenty of ways to do this with one SET statement.&amp;nbsp; Here's one more:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set work.dummydata (where=(flag1=1));&lt;/P&gt;
&lt;P&gt;if flag2=1 or (flag2=0 and flag3=1);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Nov 2017 16:36:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Urgent-Using-several-set-options-in-a-datastep/m-p/415247#M280112</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-11-21T16:36:24Z</dc:date>
    </item>
    <item>
      <title>Re: Urgent: Using several set- options in a datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Urgent-Using-several-set-options-in-a-datastep/m-p/415248#M280113</link>
      <description>Hi RW9,&lt;BR /&gt;&lt;BR /&gt;Absolutly im trying to fight SAS. Im still a rookie and my know-how is very limited. Therefore i have to go trial by fire and learn by experience. And as i struggle with my problems, eventually i will learn the SAS-way &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;I appreciate both your and Astoundings input. I will look into it and see i</description>
      <pubDate>Tue, 21 Nov 2017 16:42:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Urgent-Using-several-set-options-in-a-datastep/m-p/415248#M280113</guid>
      <dc:creator>Shawnty</dc:creator>
      <dc:date>2017-11-21T16:42:34Z</dc:date>
    </item>
  </channel>
</rss>

