BookmarkSubscribeRSS Feed
mmkr
Quartz | Level 8

Hi ,

When i use macro variables inside the sql i can see the values in log if i use symbol gen 

Isn't there a way to see it in the SQL? like expected output below ?

 

input :

 

%let test=abc;
%let test2=xyz;
 
data ds;
x=1;
y=2;
run;
options symbolgen;
proc sql;
create table &test._&test2. as
select *
from ds;
quit;
 
 
Log;
 
 
40         options symbolgen;
41         proc sql;
42         create table &test._&test2. as
SYMBOLGEN:  Macro variable TEST resolves to abc
SYMBOLGEN:  Macro variable TEST2 resolves to xyz
43         select *
44         from ds;
 
 
Expected output :
 
Isn't there a way to see it in the SQL? 
 
proc sql
create table abc_xyz as
seelct *
from ds;
quit;
 
 
5 REPLIES 5
PaigeMiller
Diamond | Level 26
%macro dothis;
    %let test=abc;
    %let test2=xyz;
 
    data ds;
        x=1;
        y=2;
    run;
    proc sql;
        create table &test._&test2. as select * from ds;
    quit;
%mend;
options mprint;
%dothis
--
Paige Miller
mmkr
Quartz | Level 8

Thank you !!

Does that work if we eliminate the macro as well?

mmkr
Quartz | Level 8

It is not working if we remove %macro ,could you please let me know if we have any other option ?

Tom
Super User Tom
Super User

If you want to see the value in the log use the %PUT statement.

%put &=test &=test2 ;
proc sql;
create table &test._&test2. as
select *
from ds;
quit;

Note: In this case you don't really need to see the value of the macro variables because the NOTE in the SAS log about the dataset being created will include the name of the dataset.

PaigeMiller
Diamond | Level 26

@mmkr wrote:

It is not working if we remove %macro ,could you please let me know if we have any other option ?


No other option that I know of. Why would having working code inside a macro be a problem that has to be avoided with some other solution?

--
Paige Miller

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 5 replies
  • 1276 views
  • 1 like
  • 3 in conversation