BookmarkSubscribeRSS Feed
mmkr
Obsidian | Level 7

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
Obsidian | Level 7

Thank you !!

Does that work if we eliminate the macro as well?

mmkr
Obsidian | Level 7

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

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 495 views
  • 1 like
  • 3 in conversation