Hi, All:
I have a question about how to display macro variable value. Example is below.
%let val=100;
data test;
x=50;
call symputx("val", x);
%put NotUpdated? = &val.;
run;
%put Updated = &val.;
In my actual situation, I want to display updated value to SAS log, before DATA step completed.
I think, this problem is caused by the timing at which %PUT statement submitted, but I have no ideas to resolve.
Any advice is welcome. Thanks in advance.
If you want to show the value you are putting into the macro variable just do that.
data test;
x=50;
call symputx("val", x);
put 'NOTE: Macro variable VAL was set to ' x ;
run;
You can use SYMGET to retrieve the value. But why?
data test;
x=50;
call symputx("val", x);
val=symgetn('val');
put val=;
run;
%put Updated = &val.;
If you want to show the value you are putting into the macro variable just do that.
data test;
x=50;
call symputx("val", x);
put 'NOTE: Macro variable VAL was set to ' x ;
run;
data_null__-san & Tom-san:
Thank you for quick reply.
I said, this problem might be from the timing at which %PUT subimitted, but it was my mistake. I didn't notice CALL SYMPUTX stored macro variable at only DATA step end (maybe).
In my actual case, I had used %DO loops in DATA step, and I wanted to display macro variable at each loop. And this issue occurred.
Thanks anyway!
@KentaMURANAKA wrote:
data_null__-san & Tom-san:
Thank you for quick reply.
I said, this problem might be from the timing at which %PUT subimitted, but it was my mistake. I didn't notice CALL SYMPUTX stored macro variable at only DATA step end (maybe).
In my actual case, I had used %DO loops in DATA step, and I wanted to display macro variable at each loop. And this issue occurred.
Thanks anyway!
You can't use a %DO loop IN a data step.
You can use a %DO loop to generate part of a data step. For example in this code
data want;
x=5;
%do i=1 to 3 ;
y&i = x;
%end;
run;
The macro code executes first and then SAS will have this program code to run:
data want;
x=5;
y1=x;
y2=x;
y3=x;
run;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.