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

Hello

I want to create multiple macro variables based on the data set macro_var_help.

In the data set 2 columns(First columns is values ,Second column is macro var name)

The following macro variables should be created:

Today(value 1903)

NextQ(value 1906)

Q3(value 1912)

Jan21(value 2101)

Apr21(value2104)

last(value2108),

What is the way to do it based on the data set values?

Data macro_var_help;
input YYMM name $;
cards;
1903 Today
1906 NextQ
1912 Q3
2101 Jan21
2104 Apr21
2108 last
;
Run;
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

CALL SYMPUTX(), look at  the third parameter option in the documentation to control if it's a global or local macro variable. 

 

data _null_;
set macro_var_help;

call symputx(name, YYMM);

run;

%put &today.;
%put &Jan21.;
%put &Q3.;
%put &last.;

@Ronein wrote:

Hello

I want to create multiple macro variables based on the data set macro_var_help.

In the data set 2 columns(First columns is values ,Second column is macro var name)

The following macro variables should be created:

Today(value 1903)

NextQ(value 1906)

Q3(value 1912)

Jan21(value 2101)

Apr21(value2104)

last(value2108),

What is the way to do it based on the data set values?

Data macro_var_help;
input YYMM name $;
cards;
1903 Today
1906 NextQ
1912 Q3
2101 Jan21
2104 Apr21
2108 last
;
Run;

 

View solution in original post

2 REPLIES 2
Reeza
Super User

CALL SYMPUTX(), look at  the third parameter option in the documentation to control if it's a global or local macro variable. 

 

data _null_;
set macro_var_help;

call symputx(name, YYMM);

run;

%put &today.;
%put &Jan21.;
%put &Q3.;
%put &last.;

@Ronein wrote:

Hello

I want to create multiple macro variables based on the data set macro_var_help.

In the data set 2 columns(First columns is values ,Second column is macro var name)

The following macro variables should be created:

Today(value 1903)

NextQ(value 1906)

Q3(value 1912)

Jan21(value 2101)

Apr21(value2104)

last(value2108),

What is the way to do it based on the data set values?

Data macro_var_help;
input YYMM name $;
cards;
1903 Today
1906 NextQ
1912 Q3
2101 Jan21
2104 Apr21
2108 last
;
Run;

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1401 views
  • 0 likes
  • 3 in conversation