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

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

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 1324 views
  • 0 likes
  • 3 in conversation