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

hello. i want to insert macro variable in the middle of specific word.

example is as follows...

 

%macro test(name=);

proc sql;
create table.&namea as
select *
from mywork.sample
;quit;

%mend test;

%test(name=sample);

 

using macro, i want to make this.

 

proc sql;
create table.samplea as
select *
from mywork.sample
;quit;

 

however, as you might expect, error statement appears in log screen. &namea wasn't converted into 'samplea'

instead, SAS recoganize '&namea' as one complete variable.

 

i want to make SAS recognize '&namea' as &name+a, conclusively, 'simplea'

 

I would really appreciate your help. thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star

Try this:

 

%macro test(name=);

proc sql;
create table.&name.a as
select *
from mywork.sample
;quit;

%mend test;

%test(name=sample);

View solution in original post

5 REPLIES 5
SASKiwi
PROC Star

Try this:

 

%macro test(name=);

proc sql;
create table.&name.a as
select *
from mywork.sample
;quit;

%mend test;

%test(name=sample);
ballardw
Super User
%macro test(name=);

proc sql;
   create  table   &name.a   as
   select *
   from mywork.sample
   ;
quit;

%mend test;

%test(name=sample);
s_lassen
Meteorite | Level 14

The problem seems to be that there is a syntax error in the code you are submitting (and in the code that you are trying to generate):

You submitted "create table.&namea", I think it should be "create table &namea", with a space instead of the dot.

km0927
Obsidian | Level 7

thanks all. due to my submitting of master's graduation paper, i couldn't care less about this project.

 

i'm sorry for not accepting answer. due to my carelessness, maybe you all have wondered why answers were not accepted, though it was right.

 

thanks for all your help.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 3164 views
  • 0 likes
  • 5 in conversation