BookmarkSubscribeRSS Feed
Lusamai
Calcite | Level 5

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 the 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 resolve 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. ==>> 1 202103 12103 SALES&P1YYMM1t..log and if I don't assign anything to the macro variable test it works fine. SYMBOLGEN: Macro variable I resolve to 1 SYMBOLGEN: && resolves to &. SYMBOLGEN:

The macro variable I resolve to 1 SYMBOLGEN: Macro variable MNTH1 resolves to 202103 SYMBOLGEN: && resolves to &. SYMBOLGEN: Macro variable I resolve to 1 SYMBOLGEN: Macro variable P1YYMM1 resolves to 12103 SYMBOLGEN: Macro variable PNME resolves to SALES SYMBOLGEN: && resolves to &. SYMBOLGEN: Macro variable I resolve to 1 SYMBOLGEN: Macro variable TST resolves to SYMBOLGEN: Macro variable P1YYMM1 resolves to 12103 i==>> 1 202103 12103 SALES12103.log

3 REPLIES 3
ballardw
Super User

Please paste code or log text in either a text box, opened on the forum sing the </> icon, or a code box opened with the "running man" icon.

That is next to impossible to read or follow.

 

One suspects to have any chance of determining what is incorrect requires:

1) the entire program code of the macro Strlog

2) the statement that calls the macro

3) the values of the macro variables that it seems you may be using for parameters to the macro

 

Style comment: Multiple uses of %str for parameters of a macro means that you may want to reconsider what/how you are passing those values. I pass lots of directory paths and file name constructs without any use of %str. This goes double for indirect macro references, the && parameter.

 

Place a %PUT statement or two before the macro call to show the values of the parameters sent to that macro to verify that what the macro is getting is what you intended.

If the call to this macro is inside another macro then comment out the call to this macro and just use the %put to see the parameters you are passing. Or perhaps make a stripped version of the looping construct to just generate these the parameters.

The relative simplicity of Proc Printto, which would be the natural way to address logs, seems like the need for a separate macro to call the Proc would be unlikely and you may be adding complexity not needed.

 


@Lusamai wrote:

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 the 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 resolve 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. ==>> 1 202103 12103 SALES&P1YYMM1t..log and if I don't assign anything to the macro variable test it works fine. SYMBOLGEN: Macro variable I resolve to 1 SYMBOLGEN: && resolves to &. SYMBOLGEN:

The macro variable I resolve to 1 SYMBOLGEN: Macro variable MNTH1 resolves to 202103 SYMBOLGEN: && resolves to &. SYMBOLGEN: Macro variable I resolve to 1 SYMBOLGEN: Macro variable P1YYMM1 resolves to 12103 SYMBOLGEN: Macro variable PNME resolves to SALES SYMBOLGEN: && resolves to &. SYMBOLGEN: Macro variable I resolve to 1 SYMBOLGEN: Macro variable TST resolves to SYMBOLGEN: Macro variable P1YYMM1 resolves to 12103 i==>> 1 202103 12103 SALES12103.log


 

ballardw
Super User

After seeing this post on the exact same problem named macro

https://communities.sas.com/t5/SAS-Programming/how-do-i-resolve-a-Macro-variable/m-p/813307

 

I suggest you read that thread. Since you are not the poster of that thread (are you?) I won't merge this thread with that one which I normally would with basically identical posts..

 

Read that other post carefully.

 

 

Tom
Super User Tom
Super User

Please explain WHAT you are trying to do?

Is the goal to create a file name of SALES12103.log from the separated pieces SALES, 12103, and .log ?

Then why not just DO that.

So let's start by initializing your input macro variables,

%let DIRNME=c:\downloads;
%let PNME=SALES ;
%let P1YYMM1=12103;
%let I=1;

Now we can use them to generate a new macro variable with the name you want.  Let's call it LOGNAME.

%let logname=&DirNme.\LOGS;
%let logname=&logname\&pnme;
%let logname=&logname.&&p1yymm&i;
%let logname=&logname..log;

Results:

435  %put &=logname;
LOGNAME=c:\downloads\LOGS\SALES12103.log

Now just use that in your macro call.

%StrLog
(PName=%str(&PName )
,PrinttoName = &logname 
,ClearLog=N
); 

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!

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
  • 583 views
  • 1 like
  • 3 in conversation