I've to test for number of observations in the WANT dataset as per the code (similar) 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.
data nobs_test;
set want;
if nobs gt 0 then output; /*Need code to test for obs in WANT dataset*/
FLT_Id=&f_id.;
run;
Hi @David_Billa
You can try this code. Hope this help!
proc sql noprint;
select count(*) into: obsnumber from want; /* Retrieve the number of observations in the dataset */
quit;
%if &obsnumber > 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=&f_id.;
run;
%end;
Best,
Hi @David_Billa
You can try this code. Hope this help!
proc sql noprint;
select count(*) into: obsnumber from want; /* Retrieve the number of observations in the dataset */
quit;
%if &obsnumber > 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=&f_id.;
run;
%end;
Best,
Hello,
In the following program, the call execute instruction is executed only if the dataset in the preceding set instruction
contains data.
data want1;
x=1; output;
x=3; output;
run;
data want2;
set want1;
stop;
run;
%macro create_ds(in, out);
data _NULL_;
set &in.;
call execute("data &out.; set &in.; FLT_Id=&f_id.; run;");
stop;
run;
%mend;
%let f_id=x;
%create_ds(want1, nobs_test1);
%create_ds(want2, nobs_test2);
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 16. 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.