<?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 Insert only when there is a observation in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Insert-only-when-there-is-a-observation/m-p/594963#M171078</link>
    <description>&lt;P&gt;In the the following code, I would like to write a data to the dataset&amp;nbsp;'oper_flt'&amp;nbsp;only if there is a Observation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table temp as select * from &amp;amp;table_name
 where &amp;amp;where ;
run;

data oper_flt;
set temp;
/*Need a condition to check for Observation and insert a data only if there is a Observation otherwise do not insert any data*/
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 09 Oct 2019 07:11:20 GMT</pubDate>
    <dc:creator>David_Billa</dc:creator>
    <dc:date>2019-10-09T07:11:20Z</dc:date>
    <item>
      <title>Insert only when there is a observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Insert-only-when-there-is-a-observation/m-p/594963#M171078</link>
      <description>&lt;P&gt;In the the following code, I would like to write a data to the dataset&amp;nbsp;'oper_flt'&amp;nbsp;only if there is a Observation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table temp as select * from &amp;amp;table_name
 where &amp;amp;where ;
run;

data oper_flt;
set temp;
/*Need a condition to check for Observation and insert a data only if there is a Observation otherwise do not insert any data*/
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 09 Oct 2019 07:11:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Insert-only-when-there-is-a-observation/m-p/594963#M171078</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2019-10-09T07:11:20Z</dc:date>
    </item>
    <item>
      <title>Re: Insert only when there is a observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Insert-only-when-there-is-a-observation/m-p/594968#M171081</link>
      <description>&lt;P&gt;hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The set instruction will exit the data step whenever there is no further observation to read.&lt;/P&gt;
&lt;P&gt;So, if your dataset is empty, every instruction after the set instruction will be ignored&lt;/P&gt;
&lt;P&gt;and the output dataset will also be empty.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;21   proc sql noprint;
22   CREATE TABLE temp AS
23   SELECT * FROM sashelp.class
24   WHERE AGE&amp;lt;0;
NOTE: Table WORK.TEMP created, with 0 rows and 5 columns.

25   quit;
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


26
27   data want;
28   set temp end=eof;
29   output;
30   if eof then do;
31       AGE=10;
32       output;
33   end;
34   run;

NOTE: There were 0 observations read from the data set WORK.TEMP.
NOTE: The data set WORK.WANT has 0 observations and 5 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 09 Oct 2019 07:47:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Insert-only-when-there-is-a-observation/m-p/594968#M171081</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2019-10-09T07:47:10Z</dc:date>
    </item>
    <item>
      <title>Re: Insert only when there is a observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Insert-only-when-there-is-a-observation/m-p/594969#M171082</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;Maybe you can try this :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this help&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table temp as select * from &amp;amp;table_name where &amp;amp;where;
quit;

/* -&amp;gt; The macrovariable sqlobs is automatically created and contains the number of observations */

%if &amp;amp;sqlobs &amp;gt; 0 %then %do; /* Test if there are observations in the dataset and process the following data step conditionally to the result */

data oper_flt;
	set temp;
run;

%end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 09 Oct 2019 07:52:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Insert-only-when-there-is-a-observation/m-p/594969#M171082</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2019-10-09T07:52:25Z</dc:date>
    </item>
  </channel>
</rss>

