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