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);
Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.
Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.
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.