EXIST is a function provided by SAS, that you determines if a data set exists. You need to use it.
%EXIST is a macro that you wrote, and does other things.
The proper call to the macro, in the last line of your program is:
%EXIST
and not
%EXIST;
SAS uses semi-colon to mark the end of a statement (both regular SAS statements and macro processor statements). So in some cases having an extra semi-colon can change the meaning of the code by terminating a statement too early.
But note that this is not really an important distinction in this case. If the dataset exists then having the extra semi-colon after the macro call means that instead of running this code:
proc sql noprint;
select put(min(date),yymmn4.)
into :Mon
from trans_tbl;
quit;
You will have run this code instead:
proc sql noprint;
select put(min(date),yymmn4.)
into :Mon
from trans_tbl;
quit;;
SAS will see that extra semi-colon as an empty statement and so not do anything different that it would without it.
True, but it can be an important distinction in other cases, and in my opinion, putting a semicolon after the call to a macro is a bad habit to get into.
If you are using a reasonably recent release of SAS you don't need do define the macro. Simple %IF/%THEN/%DO/%END/%ELSE/%DO blocks like that will work in open code.
%if %sysfunc(exist(trans_tbl)) %then %do;
proc sql noprint;
select put(min(date),yymmn4.)
into :Mon
from trans_tbl;
quit;
%end;
%else do;
%let Mon=2009;
%end;
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!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: