<?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 nobs is 0 then create a new observation in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/If-nobs-is-0-then-create-a-new-observation/m-p/710790#M218870</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;data conv1c;
 set sashelp.class;
 stop;
run;




%let dsid = %sysfunc( open(conv1c) );
%global nobss;
%let nobss = %sysfunc( attrn(&amp;amp;dsid,nlobs) );
%let rc = %sysfunc( close(&amp;amp;dsid) );
%put &amp;amp;nobss;

%macro xx;
%if &amp;amp;nobss=0 %then %do;
data conv1cc;
	   status=1;output;
	   set conv1c;
   run;
%end;
%mend;


%xx &lt;/PRE&gt;</description>
    <pubDate>Tue, 12 Jan 2021 12:16:44 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2021-01-12T12:16:44Z</dc:date>
    <item>
      <title>If nobs is 0 then create a new observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-nobs-is-0-then-create-a-new-observation/m-p/710778#M218858</link>
      <description>&lt;P&gt;Dear SAS community:&lt;/P&gt;&lt;P&gt;I would like to write a new observation when a dataset set presents 0 observations.&lt;/P&gt;&lt;P&gt;For example, conv1c is an empty dataset (nobs=0) which is checked with the following macro.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let dsid = %sysfunc( open(conv1c) );
%global nobss;
%let nobss = %sysfunc( attrn(&amp;amp;dsid,nobs) );
%let rc = %sysfunc( close(&amp;amp;dsid) );
%put &amp;amp;nobss;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So far so good! the problem is now:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data conv1cc;
	set conv1c;
	if &amp;amp;nobss=0 then status=1;
 run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;A similar problem has been posted here:&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Programming/How-to-test-for-zero-observations-and-still-be-in-control/td-p/80447" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/How-to-test-for-zero-observations-and-still-be-in-control/td-p/80447&lt;/A&gt;&amp;nbsp;(but is not quite the same)&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jan 2021 11:12:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-nobs-is-0-then-create-a-new-observation/m-p/710778#M218858</guid>
      <dc:creator>ptadgerv</dc:creator>
      <dc:date>2021-01-12T11:12:34Z</dc:date>
    </item>
    <item>
      <title>Re: If nobs is 0 then create a new observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-nobs-is-0-then-create-a-new-observation/m-p/710779#M218859</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data conv1cc;
    if _N_=1 and last then do;
        status=1;
        output;
    end;
    set conv1c end=last;
    output;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 12 Jan 2021 11:26:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-nobs-is-0-then-create-a-new-observation/m-p/710779#M218859</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2021-01-12T11:26:53Z</dc:date>
    </item>
    <item>
      <title>Re: If nobs is 0 then create a new observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-nobs-is-0-then-create-a-new-observation/m-p/710781#M218861</link>
      <description>&lt;P&gt;You don't need to check the number of obs with, just use nobs-option:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.EmptyClass;
   set sashelp.class;
   where Age &amp;lt; 10;

   keep Name;
run;

data NewClass;
   if 0 then set work.EmptyClass;

   if _nobs = 0 then do;
      Name = 'Alex';
      output;
   end;
   set work.EmptyClass nobs=_nobs;
   output;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 12 Jan 2021 11:45:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-nobs-is-0-then-create-a-new-observation/m-p/710781#M218861</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-01-12T11:45:01Z</dc:date>
    </item>
    <item>
      <title>Re: If nobs is 0 then create a new observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-nobs-is-0-then-create-a-new-observation/m-p/710782#M218862</link>
      <description>&lt;P&gt;If I understand you correct, you do not need a macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   set sashelp.class;
   stop;
run;

data want;
   if n = 0 then output;
   set have nobs=n;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 12 Jan 2021 11:45:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-nobs-is-0-then-create-a-new-observation/m-p/710782#M218862</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-01-12T11:45:17Z</dc:date>
    </item>
    <item>
      <title>Re: If nobs is 0 then create a new observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-nobs-is-0-then-create-a-new-observation/m-p/710785#M218865</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/242457"&gt;@ptadgerv&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Dear SAS community:&lt;/P&gt;
&lt;P&gt;I would like to write a new observation when a dataset set presents 0 observations.&lt;/P&gt;
&lt;P&gt;For example, conv1c is an empty dataset (nobs=0) which is checked with the following macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let dsid = %sysfunc( open(conv1c) );
%global nobss;
%let nobss = %sysfunc( attrn(&amp;amp;dsid,nobs) );
%let rc = %sysfunc( close(&amp;amp;dsid) );
%put &amp;amp;nobss;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So far so good! the problem is now:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data conv1cc;
	set conv1c;
	if &amp;amp;nobss=0 then status=1;
 run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;A similar problem has been posted here:&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Programming/How-to-test-for-zero-observations-and-still-be-in-control/td-p/80447" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/SAS-Programming/How-to-test-for-zero-observations-and-still-be-in-control/td-p/80447&lt;/A&gt;&amp;nbsp;(but is not quite the same)&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I think you may be looking for something similar to&lt;/P&gt;
&lt;PRE&gt;%let dsid = %sysfunc( open(conv1c) );
%global nobss;
%let nobss = %sysfunc( attrn(&amp;amp;dsid,nobs) );
%let rc = %sysfunc( close(&amp;amp;dsid) );
%put &amp;amp;nobss;
%if &amp;amp;nobss = 0 %then %do;
   data conv1cc;
	   set conv1c;
	   status=1;
          &amp;lt;or what ever you mean by New observation&amp;gt;
   run;
%end;
%else %do;
   &amp;lt;what ever is appropriate when the 
    count is &amp;gt; 0 
   &amp;gt;
%end;&lt;/PRE&gt;
&lt;P&gt;Since you are working with macro language then use the test of the MACRO variable to decide what code to generate.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jan 2021 11:54:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-nobs-is-0-then-create-a-new-observation/m-p/710785#M218865</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-01-12T11:54:09Z</dc:date>
    </item>
    <item>
      <title>Re: If nobs is 0 then create a new observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-nobs-is-0-then-create-a-new-observation/m-p/710790#M218870</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;data conv1c;
 set sashelp.class;
 stop;
run;




%let dsid = %sysfunc( open(conv1c) );
%global nobss;
%let nobss = %sysfunc( attrn(&amp;amp;dsid,nlobs) );
%let rc = %sysfunc( close(&amp;amp;dsid) );
%put &amp;amp;nobss;

%macro xx;
%if &amp;amp;nobss=0 %then %do;
data conv1cc;
	   status=1;output;
	   set conv1c;
   run;
%end;
%mend;


%xx &lt;/PRE&gt;</description>
      <pubDate>Tue, 12 Jan 2021 12:16:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-nobs-is-0-then-create-a-new-observation/m-p/710790#M218870</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-01-12T12:16:44Z</dc:date>
    </item>
    <item>
      <title>Re: If nobs is 0 then create a new observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-nobs-is-0-then-create-a-new-observation/m-p/710943#M218935</link>
      <description>&lt;P&gt;Thanks for so many solutions!&lt;/P&gt;&lt;P&gt;Now, the problem is to choose the best one &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I will require some time to do it (please be patient, too many deadlines this week &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&amp;nbsp; &amp;nbsp;)&amp;nbsp;&lt;/P&gt;&lt;P&gt;Today, in my problem..., I combined several of the proposed solutions in one approach. That's why is difficult to choose just one solution (but I'll do it).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jan 2021 23:30:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-nobs-is-0-then-create-a-new-observation/m-p/710943#M218935</guid>
      <dc:creator>ptadgerv</dc:creator>
      <dc:date>2021-01-12T23:30:37Z</dc:date>
    </item>
  </channel>
</rss>

