BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
ppinedo
Fluorite | Level 6

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.

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

&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)
--
Paige Miller

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

&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)
--
Paige Miller
Tom
Super User Tom
Super User

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;

 

ppinedo
Fluorite | Level 6

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"?? 🤔

 
Tom
Super User Tom
Super User

typo.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 4 replies
  • 358 views
  • 0 likes
  • 3 in conversation