<?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 write the logic or a macro to output a dataset on the condition that 1st data set has 0 o in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-write-the-logic-or-a-macro-to-output-a-dataset-on-the/m-p/794767#M254849</link>
    <description>&lt;P&gt;That's not so hard:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;                   
  if nobs=0 then set _empty; 
  set practice1 nobs=nobs;   
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It looks kind of strange, as the NOBS variable is referred before the PRACTICE1 dataset is read, but it works (NOBS is set at compile time). If you swap the two statements, it will not work, because the datastep then terminates at SET PRACTICE1.&lt;/P&gt;</description>
    <pubDate>Mon, 07 Feb 2022 11:19:21 GMT</pubDate>
    <dc:creator>s_lassen</dc:creator>
    <dc:date>2022-02-07T11:19:21Z</dc:date>
    <item>
      <title>How to write the logic or a macro to output a dataset on the condition that 1st data set has 0 obs?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-write-the-logic-or-a-macro-to-output-a-dataset-on-the/m-p/794597#M254793</link>
      <description>&lt;P&gt;For example, if we use the following data sets:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data practice;
      input name $ fav_color $ no.;
datalines;
mark blue 3
lisa red 9
laquisha orange 2
shauna blue 8
ray purple 1
;
run;

data practice1;
   set practice;

if fav_color="pink";
run;

data _empty;
infile datalines dsd dlm ",";
  input name $ fav_color $ no.;
datalines;
 , There is no one with this fav_color,
;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Since i try to return back a data set with people who only liked "pink", and no one existed in the data set, there are 0 observations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How do i have it so that i could use either some kind of code with complicated logic or a macro to be able to return that says effectively that&lt;/P&gt;
&lt;P&gt;if this dataset has 0 observations, please return back the work._empty data set?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 04 Feb 2022 20:13:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-write-the-logic-or-a-macro-to-output-a-dataset-on-the/m-p/794597#M254793</guid>
      <dc:creator>Hello_there</dc:creator>
      <dc:date>2022-02-04T20:13:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to write the logic or a macro to output a dataset on the condition that 1st data set has 0 o</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-write-the-logic-or-a-macro-to-output-a-dataset-on-the/m-p/794598#M254794</link>
      <description>&lt;H1 class="xisDoc-title"&gt;Example 13: Print Information to the Output Window If a Data Set Is Empty&lt;/H1&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/p011imau3tm4jen1us2a45cyenz9.htm" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/p011imau3tm4jen1us2a45cyenz9.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/252358"&gt;@Hello_there&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;For example, if we use the following data sets:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data practice;
      input name $ fav_color $ no.;
datalines;
mark blue 3
lisa red 9
laquisha orange 2
shauna blue 8
ray purple 1
;
run;

data practice1;
   set practice;

if fav_color="pink";
run;

data _empty;
infile datalines dsd dlm ",";
  input name $ fav_color $ no.;
datalines;
 , There is no one with this fav_color,
;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Since i try to return back a data set with people who only liked "pink", and no one existed in the data set, there are 0 observations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How do i have it so that i could use either some kind of code with complicated logic or a macro to be able to return that says effectively that&lt;/P&gt;
&lt;P&gt;if this dataset has 0 observations, please return back the work._empty data set?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Feb 2022 20:16:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-write-the-logic-or-a-macro-to-output-a-dataset-on-the/m-p/794598#M254794</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-02-04T20:16:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to write the logic or a macro to output a dataset on the condition that 1st data set has 0 o</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-write-the-logic-or-a-macro-to-output-a-dataset-on-the/m-p/794767#M254849</link>
      <description>&lt;P&gt;That's not so hard:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;                   
  if nobs=0 then set _empty; 
  set practice1 nobs=nobs;   
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It looks kind of strange, as the NOBS variable is referred before the PRACTICE1 dataset is read, but it works (NOBS is set at compile time). If you swap the two statements, it will not work, because the datastep then terminates at SET PRACTICE1.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Feb 2022 11:19:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-write-the-logic-or-a-macro-to-output-a-dataset-on-the/m-p/794767#M254849</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2022-02-07T11:19:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to write the logic or a macro to output a dataset on the condition that 1st data set has 0 o</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-write-the-logic-or-a-macro-to-output-a-dataset-on-the/m-p/794785#M254859</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data practice;
      input name $ fav_color $ no;
datalines;
mark blue 3
lisa red 9
laquisha orange 2
shauna blue 8
ray purple 1
;
run;

data practice1;
   set practice;

if fav_color="pink";
run;

data _empty;
retain name fav_color no1;
length name $50 fav_color $50;

infile datalines dsd dlm=",";

no1=put(no, best.);

if no1 eq . then no1= " ";

drop no;

rename no1=no;

  input name $ fav_color $ no;
datalines;
 , There is no one with this fav_color,
;
run;


/****solution*****/

data want;                   
  if nobs=0 then set _empty; 
  set practice1 nobs=nobs;   
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thanks for replying!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Unfortunately it did not work for me.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this example, practice1 has 0 obs, and I'm looking for the logic that says return back work._empty bc practice 1 had 0 obs.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I ran your code, it returned back an empty data set.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Feb 2022 13:38:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-write-the-logic-or-a-macro-to-output-a-dataset-on-the/m-p/794785#M254859</guid>
      <dc:creator>Hello_there</dc:creator>
      <dc:date>2022-02-07T13:38:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to write the logic or a macro to output a dataset on the condition that 1st data set has 0 o</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-write-the-logic-or-a-macro-to-output-a-dataset-on-the/m-p/794798#M254865</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/76464"&gt;@s_lassen&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;That's not so hard:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;                   
  if nobs=0 then set _empty; 
  set practice1 nobs=nobs;   
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It looks kind of strange, as the NOBS variable is referred before the PRACTICE1 dataset is read, but it works (NOBS is set at compile time). If you swap the two statements, it will not work, because the datastep then terminates at SET PRACTICE1.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That won't work.&amp;nbsp; When PRACTICE1 is empty the first iteration will still read past the end of PRACTICE1 so no observations will be written.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perhaps you meant to include an ELSE?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;                   
  if nobs=0 then set _empty; 
  else set practice1 nobs=nobs;   
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 07 Feb 2022 14:40:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-write-the-logic-or-a-macro-to-output-a-dataset-on-the/m-p/794798#M254865</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-02-07T14:40:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to write the logic or a macro to output a dataset on the condition that 1st data set has 0 o</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-write-the-logic-or-a-macro-to-output-a-dataset-on-the/m-p/794810#M254869</link>
      <description>Thanks this worked!</description>
      <pubDate>Mon, 07 Feb 2022 15:22:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-write-the-logic-or-a-macro-to-output-a-dataset-on-the/m-p/794810#M254869</guid>
      <dc:creator>Hello_there</dc:creator>
      <dc:date>2022-02-07T15:22:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to write the logic or a macro to output a dataset on the condition that 1st data set has 0 o</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-write-the-logic-or-a-macro-to-output-a-dataset-on-the/m-p/794811#M254870</link>
      <description>Thanks, s_lassen, for your help! I got it working because of your code.</description>
      <pubDate>Mon, 07 Feb 2022 15:24:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-write-the-logic-or-a-macro-to-output-a-dataset-on-the/m-p/794811#M254870</guid>
      <dc:creator>Hello_there</dc:creator>
      <dc:date>2022-02-07T15:24:07Z</dc:date>
    </item>
  </channel>
</rss>

