BookmarkSubscribeRSS Feed
Ronein
Onyx | Level 15

Hello

I want to print a message in results window If the data set is empty .

I also want to add title to  print in case that data set not empty.

Error:

 

75 call execute(Title 'information class_tbl';'proc print data=work.class_tbl2 noobs; run;');
_______________________ ______________________________________________
388 180
200
ERROR 388-185: Expecting an arithmetic operator.

ERROR 180-322: Statement is not valid or it is used out of proper order.

ERROR 200-322: The symbol is not recognized and will be ignored.

 

data class_tbl;
set sashelp.class;
run;

data class_tbl2;
set sashelp.class;
run;
proc sql noprint;
delete from work.class_tbl2
where Age < 20;
quit;
 


data use_this_if_no_obs;
msg='No Data';
run;

data _null_;
dsnid=open('work.class_tbl');

if dsnid then do;
nobs=attrn(dsnid, 'nobs');
end;

if nobs=0 then do;
call execute(Title 'information class_tbl'; 'proc print data=use_this_if_no_obs noobs; run;');
end;

else do;
call execute('proc print data=work.class_tbl  noobs; run;');
end;

rc = close(dsnid);
run;


data _null_;
dsnid=open('work.class_tbl2');

if dsnid then do;
nobs=attrn(dsnid, 'nobs');
end;

if nobs=0 then do;
call execute('proc print data=use_this_if_no_obs noobs; run;');
end;

else do;
call execute(Title 'information class_tbl';'proc print data=work.class_tbl2  noobs; run;');
end;

rc = close(dsnid);
run;

 

1 REPLY 1
Kurt_Bremser
Super User

To conditionally execute code, use %IF %THEN %DO %END %ELSE %DO %END. CALL EXECUTE is good if you need to create code from data step values, but for a simpke yes/no decision macro language is easier. Retrieve the number of observations in PROC SQL with SELECT INTO from DICTIONARY.TABLES.

The word title without quotes around it in your call execute is interpreted by the data step compiler as a variable name.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 535 views
  • 0 likes
  • 2 in conversation