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

Hello,

I want to create variables and dataset with a macro. Part of the name of those is one of the parameter of this macro.

When the parameter is located at the end of the name, it works.

Example:

%macro test(year);

data work.bd&year;

variable&years=variable;

run;

%mend test;

%test(2007);

How can I do the same, but with the parameter at the beginningof the name? This doesn't work because the parameter is not recognise:

%macro test(year);

data work.&yearbd;

&yearvariable=variable;

run;

%mend test;

%test(2007);

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

The first letter of a dataset name or variable can't be a digit, it is illegal.

I don't understand why would you want do that.You can use a underline before it to make it legal.

or use options validvarname=any ; to make it happen.

options validvarname=any ;

%macro test(year);

data work._&year.bd ;

"&year.variable"n=1; output;

run;

%mend test;

%test(2007);

Message was edited by: xia keshan

View solution in original post

2 REPLIES 2
Ksharp
Super User

The first letter of a dataset name or variable can't be a digit, it is illegal.

I don't understand why would you want do that.You can use a underline before it to make it legal.

or use options validvarname=any ; to make it happen.

options validvarname=any ;

%macro test(year);

data work._&year.bd ;

"&year.variable"n=1; output;

run;

%mend test;

%test(2007);

Message was edited by: xia keshan

Demographer
Pyrite | Level 9

Thanks. In fact, the problem was the . between the two terms.

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
  • 2 replies
  • 1226 views
  • 0 likes
  • 2 in conversation