BookmarkSubscribeRSS Feed
Ronein
Meteorite | Level 14

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.

sas-innovate-white.png

Missed SAS Innovate in Orlando?

Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.

 

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
  • 453 views
  • 0 likes
  • 2 in conversation