BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Ronein
Meteorite | Level 14
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
Meteorite | Level 14
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;

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