BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Ronein
Onyx | Level 15
Should i use %exist or exist??
Can you explain please .

May you show the full code of your solution?
PaigeMiller
Diamond | Level 26

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;

--
Paige Miller
Tom
Super User Tom
Super User

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.

PaigeMiller
Diamond | Level 26

@Tom 

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.

--
Paige Miller
Ronein
Onyx | Level 15
I was not aware of it and i used to call macro with semi colon.
Now after your important remark i will chage my habit.
My only question what is the logic that after each statement we put semicolon but ater running a macro not....???
Tom
Super User Tom
Super User

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;

Catch up on SAS Innovate 2026

Nearly 200 sessions are now available on demand with the SAS Innovate Digital Pass.

Explore 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
  • 21 replies
  • 4824 views
  • 10 likes
  • 4 in conversation