BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
KentaMURANAKA
Pyrite | Level 9

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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;

View solution in original post

4 REPLIES 4
data_null__
Jade | Level 19

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.;
Tom
Super User Tom
Super User

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;
KentaMURANAKA
Pyrite | Level 9

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!

Tom
Super User Tom
Super User

@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;

 

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1445 views
  • 6 likes
  • 3 in conversation