hello,
I can´t resolve macro variable created by SYMPUT routine.
%macro X2N(id,nombre,edad);
title "Bienvenido %upcase(&nombre), hoy es &sysdate9.";
data _null_;
call symput('now',put(time(),time5.));
run;
proc print data=y;
run;
%mend X2N;
%put NOTE- Bienvenido son las &now;
%x2n(5,pablo,23);
I get the error message: "WARNING: Apparent symbolic reference NOW not resolved.", but I don't understand why I get this message 🤔
Anyone can advise me about it??
Thanks so much.
&NOW exists inside macro %X2N, because that's where it was created. It does not exist outside of macro %X2N;
In addition, you are trying to use &NOW before it is created (the %PUT statement comes before the call to macro %X2N).
This will work, but may not be what you want.
%macro X2N(id,nombre,edad);
data _null_;
call symput('now',put(time(),time5.));
run;
%put NOTE- Bienvenido son las &now &=hora;
title "Bienvenido %upcase(&nombre), hoy es &sysdate9.";
proc print data=y;
run;
%mend X2N;
%x2n(5,pablo,23)
&NOW exists inside macro %X2N, because that's where it was created. It does not exist outside of macro %X2N;
In addition, you are trying to use &NOW before it is created (the %PUT statement comes before the call to macro %X2N).
This will work, but may not be what you want.
%macro X2N(id,nombre,edad);
data _null_;
call symput('now',put(time(),time5.));
run;
%put NOTE- Bienvenido son las &now &=hora;
title "Bienvenido %upcase(&nombre), hoy es &sysdate9.";
proc print data=y;
run;
%mend X2N;
%x2n(5,pablo,23)
Two issues.
1) You %PUT is before you call the macro that would create NOW.
2) Unless you have created the macro variable NOW before you call the macro then the macro variable NOW it creates will be LOCAL to the macro and no longer exist when the macro finishes.
You can either define the macro variable before calling the macro:
%let now=;
%x2n(5,pablo,23);
%put NOTE- Bienvenido son las &now;
Or change the macro to make sure it doesn't define NOW as logic. The quick (and dirty) method is to use the optional third argument to CALL SYMPUTX(). NOTE: unless there is some strange reason that you need the macro variable to have leading and/or trailing spaces you should never use the ancient CALL SYMPUT() method.
%macro X2N(id,nombre,edad);
title "Bienvenido %upcase(&nombre), hoy es &sysdate9.";
data _null_;
call symputX('now',put(time(),time5.),'g');
run;
proc print data=y;
run;
%mend X2N;
NOTE: If you want NOW to include leading zero when time() is before 10AM then use TOD format instead of TIME format.
But the better solution would be to only define NOW as GLOBAL when it does not already exist. Then you could call this macro from another macro that has a LOCAL macro variable named NOW and be able to see the results.
%macro X2N(id,nombre,edad);
%if not %symexist(now) %then %global now;
title "Bienvenido %upcase(&nombre), hoy es &sysdate9.";
data _null_;
call symputX('now',put(time(),time5.));
run;
proc print data=y;
run;
%mend X2N;
Thanks for you reply @PaigeMiller 👍, you are right, macro-variable is LOCAL to the macro
What do you mean " to make sure it doesn't define NOW as logic" @Tom ?? what is "logic"?? 🤔
typo.
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!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.