In the the following code, I would like to write a data to the dataset 'oper_flt' only if there is a Observation.
proc sql;
create table temp as select * from &table_name
where &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;
hello,
The set instruction will exit the data step whenever there is no further observation to read.
So, if your dataset is empty, every instruction after the set instruction will be ignored
and the output dataset will also be empty.
21 proc sql noprint;
22 CREATE TABLE temp AS
23 SELECT * FROM sashelp.class
24 WHERE AGE<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
Hi @David_Billa ,
Maybe you can try this :
Hope this help
proc sql;
create table temp as select * from &table_name where &where;
quit;
/* -> The macrovariable sqlobs is automatically created and contains the number of observations */
%if &sqlobs > 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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.