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

Hallo to all,

I desire to make my algorithm more flexible. From this reason I tried to used macro variables. I have problem to use marco variable on terminology of my data set.I want for example to have one marco variable as name,and with it i change the name of data sets.

Can someone help me?

  

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Two key things.

1) You are following the name of the macro variable you are trying to reference with a character that could be part of the name.  You can use a period to let the macro processor know where the name ends.

2) The macro processor ignores quoted strings that are bounded on the outside by single quotes.  Use double quotes for your strings that you want the macro processor to evaluate.

 

create table &colour._dataset as
  select t.*
  from colours t
  where t.colours="&colours"
;

View solution in original post

5 REPLIES 5
Patrick
Opal | Level 21

@Barney1998 Please re-read your question and consider if anyone can understand what you're asking for based on what you wrote and without any of the context that might exists in your brain.

Barney1998
Obsidian | Level 7
from example ,
proc sql;
create table colour_dataset as
select t.*
from colours t
where t.colours='yellow';
quit;

I know how to use marco variable in where statement ,the question is if exist any way to use marco variable on tables onomastics i.e
%let colour = yellow;
%let colours= yellow;


proc sql;
create table &colour_dataset as
select t.*
from colours t
where t.colours='&colours';
quit;

I want give name to the table above from marco variable,videlicet i don't must to give the name yellow_dataset manual but i use one variable colour and every time i changed its name the table name changed too, for example from yellow to red.
Thanks in advance!



Tom
Super User Tom
Super User

Two key things.

1) You are following the name of the macro variable you are trying to reference with a character that could be part of the name.  You can use a period to let the macro processor know where the name ends.

2) The macro processor ignores quoted strings that are bounded on the outside by single quotes.  Use double quotes for your strings that you want the macro processor to evaluate.

 

create table &colour._dataset as
  select t.*
  from colours t
  where t.colours="&colours"
;
Barney1998
Obsidian | Level 7
Perfect. thanks a million
Have a nice day!

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
  • 322 views
  • 0 likes
  • 4 in conversation