BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Santt0sh
Lapis Lazuli | Level 10

Hi All,

 

This might look silly, but i am not able to resolve a Macro variable.

I am trying to create log files for a program and running it in loop for multiple dates for a single .sas program.

 

Kindly suggest me on this.

%let tst = t1; /*for testing purpose*/
/*StrLog Macro creates the log file at the give location in the macro var dirname*/

%StrLog(PName=%str(&PName ),PrinttoName = %str(&DirNme.\LOGS\&PName .&&Pg1YYMM&i.&tst..log) , ClearLog=N);


LOG :

WARNING: Apparent symbolic reference P1YYMM1_T1 not resolved.
&P1YYMM1_t1..log

If i assign anything to the Macro tst, its not resolving pls check the below.

SYMBOLGEN: Macro variable I resolves to 1
SYMBOLGEN: && resolves to &.
SYMBOLGEN: Macro variable I resolves to 1
SYMBOLGEN: Macro variable MNTH1 resolves to 202103
SYMBOLGEN: && resolves to &.
SYMBOLGEN: Macro variable I resolves to 1
SYMBOLGEN: Macro variable P1YYMM1 resolves to 12103
SYMBOLGEN: Macro variable PNME resolves to SALES
SYMBOLGEN: && resolves to &.
SYMBOLGEN: Macro variable I resolves to 1
SYMBOLGEN: Macro variable TST resolves to t
WARNING: Apparent symbolic reference P1YYMM1T not resolved.
i==>> 1 202103 12103 SALES&P1YYMM1t..log


and if I don't assign anything to the macro variable tst it works fine.
SYMBOLGEN: Macro variable I resolves to 1
SYMBOLGEN: && resolves to &.
SYMBOLGEN: Macro variable I resolves to 1
SYMBOLGEN: Macro variable MNTH1 resolves to 202103
SYMBOLGEN: && resolves to &.
SYMBOLGEN: Macro variable I resolves to 1
SYMBOLGEN: Macro variable P1YYMM1 resolves to 12103
SYMBOLGEN: Macro variable PNME resolves to SALES
SYMBOLGEN: && resolves to &.
SYMBOLGEN: Macro variable I resolves to 1
SYMBOLGEN: Macro variable TST resolves to
SYMBOLGEN: Macro variable P1YYMM1 resolves to 12103
i==>> 1 202103 12103 SALES12103.log

I need to make sure it works in both the scenarios.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

You probably have over complicated things.

Please explain WHY you are calling the macro in this strange way.  Especially the first two parameter values.

%StrLog
(PName=%str(&PName )
,PrinttoName = %str(&DirNme.\LOGS\&PName .&&Pg1YYMM&i.&tst..log)
,ClearLog=N
);

For the first parameter:

Do you really want to pass in a space after the value of the external macro PNAME when passing the value into the macro as the parameter PNAME?

 

For the second parameter:

Why are you adding macro quoting around the value?  Do your directories include commas? Unbalanced parentheses?

 

Does the macro variable I really have the value 1_?  That seems really strange.  If not then were did the underscore in your error message come from?

 

Do you really want a period after the space when using PNAME to construct PRINTTONAME?  Note there is not need to use %STR() for that space as it is followed by a non space character so will not "disappear".

 

If you don't want the value of TST to become part of the macro name you are generating by appending the value of I to the string PG1YYMM then add another period after &I.  The first will mark the end of I and the second the end of PG1YYMM1_.

 

Do you have a macro variable named PG1YYMM1_ ?  If not then why have the && before PG1YYMM?

 

&DirNme.\LOGS\&PName .&&Pg1YYMM&i..&tst..log

 

View solution in original post

7 REPLIES 7
PaigeMiller
Diamond | Level 26

To debug macros, first turn on the debugging options by running this command

 

options mprint symbolgen mlogic;

Then run the macro again and show us the ENTIRE log for the macro. Please copy the log as text and then paste it into the window that appears when you click on the </> icon. DO NOT SKIP THIS STEP.

 

2021-11-26 08_27_29-Reply to Message - SAS Support Communities — Mozilla Firefox.png

 

Also show us the code for macro %StrLog

--
Paige Miller
xxformat_com
Barite | Level 11

I cannot help without a replicable example. Here I'm assuming that you call the macro in a loop.

For such circumstances I prefer to use call execute after creating a REF dataset containing all the possible values.

 

Here is an example:

 

%macro printds(ds=);
proc print data=&ds.;
run;
%mend printds;
%*printds(ds=sashelp.class);

data ref;
   set sashelp.vtable (where=(upcase(libname)='SASHELP' and 
                              upcase(memname) like 'C%'));
run;

data _null_;
    set ref;
    call execute('%printds(ds=sashelp.' || memname || ');');
run;
s_lassen
Meteorite | Level 14

I tried to recreate some of the macro resolution in your program:

 69         %let Pg1YYMM1=12103;
 70         %let I=1;
 71         %let tst=_t1;
 72         %put &&Pg1YYMM&i.&tst..log;
 WARNING: Apparent symbolic reference PG1YYMM1_T1 not resolved.
 &Pg1YYMM1_t1.log

What seems to happen is that the TST variable becomes part of the macro variable name that is resolved in the second parse through the compiler (everything from "&&" up to the double period before "log").

 

If you double the period before "&tst" as well, it may work:

 69         %let Pg1YYMM1=12103;
 70         %let I=1;
 71         %let tst=_t1;
 72         %put &&Pg1YYMM&i..&tst..log;
 12103_t1.log
PaigeMiller
Diamond | Level 26

@Santt0sh 

I specifically asked to see the ENTIRE log, as well as the macro code. You have not provided either.

--
Paige Miller
Sajid01
Meteorite | Level 14

tst itself is a macro variable. Try adding one more ampersand before it as below

%StrLog(PName=%str(&PName ),PrinttoName = %str(&DirNme.\LOGS\&PName .&&Pg1YYMM&i.&&tst..log) , ClearLog=N);
Tom
Super User Tom
Super User

You probably have over complicated things.

Please explain WHY you are calling the macro in this strange way.  Especially the first two parameter values.

%StrLog
(PName=%str(&PName )
,PrinttoName = %str(&DirNme.\LOGS\&PName .&&Pg1YYMM&i.&tst..log)
,ClearLog=N
);

For the first parameter:

Do you really want to pass in a space after the value of the external macro PNAME when passing the value into the macro as the parameter PNAME?

 

For the second parameter:

Why are you adding macro quoting around the value?  Do your directories include commas? Unbalanced parentheses?

 

Does the macro variable I really have the value 1_?  That seems really strange.  If not then were did the underscore in your error message come from?

 

Do you really want a period after the space when using PNAME to construct PRINTTONAME?  Note there is not need to use %STR() for that space as it is followed by a non space character so will not "disappear".

 

If you don't want the value of TST to become part of the macro name you are generating by appending the value of I to the string PG1YYMM then add another period after &I.  The first will mark the end of I and the second the end of PG1YYMM1_.

 

Do you have a macro variable named PG1YYMM1_ ?  If not then why have the && before PG1YYMM?

 

&DirNme.\LOGS\&PName .&&Pg1YYMM&i..&tst..log

 

Astounding
PROC Star

It's too difficult to believe everything you have posted.

 

You say you have a macro variable named PNAME.  But SAS doesn't find that.  It only finds PNME.

 

Your %LET statement says you assign a value of t1 to the macro variable TST.  But SAS finds that it resolves to t, not t1.

 

You say you have problems with a macro variable named P1YYMM1_T1.  But the original string doesn't contain an underscore, nor any code that would add an underscore to the string.

 

So I have to ignore your details as being of questionable accuracy.

 

But there is one piece that seems interesting.  You say the code (whatever it actually is) runs the first time but not the second time.  For that, I would take a wild guess at the problem lying with nesting the repeated %STR function:

PName=%str(&PName ),

Try it this way instead:

PName=%str(%unquote(&PName) ),

That's a long-shot guess, but can't hurt and might help.  

 

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
  • 7 replies
  • 769 views
  • 0 likes
  • 7 in conversation