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;

 

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
  • 1417 views
  • 6 likes
  • 3 in conversation