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;

 

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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