DATA Step, Macro, Functions and more

Problems with Macro to Create a Directory

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 18
Accepted Solution

Problems with Macro to Create a Directory

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

Accepted Solutions
Solution
‎08-03-2015 12:14 PM
Super User
Super User
Posts: 6,499

Re: Problems with Macro to Create a Directory

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


All Replies
Solution
‎08-03-2015 12:14 PM
Super User
Super User
Posts: 6,499

Re: Problems with Macro to Create a Directory

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 ;

Occasional Contributor
Posts: 18

Re: Problems with Macro to Create a Directory

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

Contributor
Posts: 34

Re: Problems with Macro to Create a Directory

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

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 231 views
  • 3 likes
  • 3 in conversation