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
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
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.
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
);
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Ready to level-up your skills? Choose your own adventure.