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.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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