<?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: Insert data only if there is any obs in input dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Insert-data-only-if-there-is-any-obs-in-input-dataset/m-p/605355#M175682</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can try this code. Hope this help!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
	select count(*) into: obsnumber from want; /* Retrieve the number of observations in the dataset */
quit;

%if &amp;amp;obsnumber &amp;gt; 0 %then %do; /* Test if there are observations in the dataset and process the following data step conditionally to the result */

data nobs_test;
	set want;
	FLT_Id=&amp;amp;f_id.;
run;

%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Best,&lt;/P&gt;</description>
    <pubDate>Tue, 19 Nov 2019 10:50:14 GMT</pubDate>
    <dc:creator>ed_sas_member</dc:creator>
    <dc:date>2019-11-19T10:50:14Z</dc:date>
    <item>
      <title>Insert data only if there is any obs in input dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Insert-data-only-if-there-is-any-obs-in-input-dataset/m-p/605350#M175679</link>
      <description>&lt;P&gt;I've to test for number of observations in the WANT dataset as per the code (similar)&amp;nbsp;below and I want to output the data to nobs_test dataset only if there is any observation in the WANT dataset. If there is no observation in the source dataset 'WANT' then the code should not create nobs_test dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data nobs_test;
set want;
if nobs gt 0 then output; /*Need code to test for obs in WANT dataset*/
FLT_Id=&amp;amp;f_id.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 19 Nov 2019 10:37:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Insert-data-only-if-there-is-any-obs-in-input-dataset/m-p/605350#M175679</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2019-11-19T10:37:38Z</dc:date>
    </item>
    <item>
      <title>Re: Insert data only if there is any obs in input dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Insert-data-only-if-there-is-any-obs-in-input-dataset/m-p/605355#M175682</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can try this code. Hope this help!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
	select count(*) into: obsnumber from want; /* Retrieve the number of observations in the dataset */
quit;

%if &amp;amp;obsnumber &amp;gt; 0 %then %do; /* Test if there are observations in the dataset and process the following data step conditionally to the result */

data nobs_test;
	set want;
	FLT_Id=&amp;amp;f_id.;
run;

%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Best,&lt;/P&gt;</description>
      <pubDate>Tue, 19 Nov 2019 10:50:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Insert-data-only-if-there-is-any-obs-in-input-dataset/m-p/605355#M175682</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2019-11-19T10:50:14Z</dc:date>
    </item>
    <item>
      <title>Re: Insert data only if there is any obs in input dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Insert-data-only-if-there-is-any-obs-in-input-dataset/m-p/605356#M175683</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the following program, the call execute instruction is executed only if the dataset in the preceding set instruction&lt;/P&gt;
&lt;P&gt;contains data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want1;
    x=1; output;
    x=3; output;
run;

data want2;
    set want1;
    stop;
run;

%macro create_ds(in, out);

    data _NULL_;
        set &amp;amp;in.;
        call execute("data &amp;amp;out.; set &amp;amp;in.; FLT_Id=&amp;amp;f_id.; run;");
        stop;
    run;

%mend;

%let f_id=x;

%create_ds(want1, nobs_test1);
%create_ds(want2, nobs_test2);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 19 Nov 2019 10:51:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Insert-data-only-if-there-is-any-obs-in-input-dataset/m-p/605356#M175683</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2019-11-19T10:51:26Z</dc:date>
    </item>
  </channel>
</rss>

