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);
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.