BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
BryanMarks
Calcite | Level 5
Hi,
I had this macro working the other day but must have accidentally changed it because it now gives me an error that the "apparent symbolic reference DIR not resolved."  The value of UVPERIOD is 150630 and the value of ProjNo is 6913, so YY resolves to 15 and QQYY resolves to 2Q15.  I'm sure it's something super obvious to someone who does a fair amount of SAS macro coding, but I'm not that person and I've already spent quite a bit of time trying to get this working again.  Any help to get this working again would be greatly appreciated!

%LET YY = %SUBSTR(&UVPERIOD,1,2);
%MACRO SETQQYY;
%IF %SUBSTR(&UVPERIOD,3,2) = 06 %THEN %LET QQYY = 2Q&YY;
%IF %SUBSTR(&UVPERIOD,3,2) = 12 %THEN %LET QQYY = 4Q&YY;
%MEND SETQQYY;
%SETQQYY;
%MACRO SETDIR;
%IF &ProjNo >= 6000 AND &ProjNo < 6500 %THEN %LET DIR = 6000-6499\&ProjNo-AWD-Market Share &QQYY\SAS Data;
%IF &ProjNo >= 6500 AND &ProjNo < 7000 %THEN %LET DIR = 6500-6999\&ProjNo-AWD-Market Share &QQYY\SAS Data;
%IF &ProjNo >= 7000 AND &ProjNo < 7500 %THEN %LET DIR = 7000-7499\&ProjNo-AWD-Market Share &QQYY\SAS Data;
%IF &ProjNo >= 7500 AND &ProjNo < 8000 %THEN %LET DIR = 7500-7999\&ProjNo-AWD-Market Share &QQYY\SAS Data;
%IF &ProjNo >= 8000 AND &ProjNo < 8500 %THEN %LET DIR = 8000-8499\&ProjNo-AWD-Market Share &QQYY\SAS Data;
%IF &ProjNo >= 8500 AND &ProjNo < 9000 %THEN %LET DIR = 8500-8999\&ProjNo-AWD-Market Share &QQYY\SAS Data;
%MEND SETDIR;
%SETDIR;
%PUT &UVPERIOD &PROJNO &YY &QQYY &DIR;
Thanks,
Bryan
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

You probably before had created the macro variable DIR before calling the macro %SETDIR so that the macro updated the existing macro variable.

If you run %SETDIR and the macro variable DIR is not yet defined then it will be created as local to SETDIR and disappear when SETDIR ends.

You can just set it first.

%let dir=<unknown> ;

%setdir;

Or you could add %GLOBAL DIR; to the macro definition.  Or better do it conditionally.

%if not %symexist(dir) %then %global dir ;

View solution in original post

3 REPLIES 3
Tom
Super User Tom
Super User

You probably before had created the macro variable DIR before calling the macro %SETDIR so that the macro updated the existing macro variable.

If you run %SETDIR and the macro variable DIR is not yet defined then it will be created as local to SETDIR and disappear when SETDIR ends.

You can just set it first.

%let dir=<unknown> ;

%setdir;

Or you could add %GLOBAL DIR; to the macro definition.  Or better do it conditionally.

%if not %symexist(dir) %then %global dir ;

BryanMarks
Calcite | Level 5

Hi, Tom!

That fixed it.  I had thought about adding the %Let Dir = ; statement prior to the %Macro statement, but hadn't tried it yet.  I was trying to remember if that was how I'd done it before but you already answered before giving that a shot.

Thanks!

Bryan

ddemilla
Fluorite | Level 6

Without knowing what is being fed into the macro I can't be entirely sure what your problem is. The error that you are receiving means that the macro variable "DIR" has not been created. This would occur if none of the above conditions were met for "ProjNo". I would begin by creating a data integrity test where you set the default value of "DIR" to "Error". Then verify that the "DIR" value has been changed before attempting to assign the libname. You can also try "options mlogic" to see how each of the above conditions are evaluating.

Best of luck,

Daniel

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 3 replies
  • 1050 views
  • 3 likes
  • 3 in conversation