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

Hy guys,

I have lost my head already finding the solution to my problem.

I have two columns VarName and VarDate

I want to assign values of VarDate to macro variables in column VarName not naming them separately one by one.

Result should be 14 macro variables with assigned values.

For example:

if I would write %put &A_10; It should return me value 14/06/2020

if I would write %put &A_11; It should return me value 12/06/2020

if I would write %put &G_11; It should return me value 31/12/2021

 

data have;
input VarName $ VarDate :ddmmyy10.;
format VarDate ddmmyy10.;
datalines;
A_10 14/06/2020
A_11 12/06/2020
B_10 30/06/2020
B_11 30/06/2020
C_10 31/05/2020
C_11 29/05/2020
D_10 30/04/2020
D_11 30/04/2020
E_10 31/03/2020
E_11 31/03/2020
F_10 29/02/2020
F_11 28/02/2020
G_10 31/12/2021
G_11 31/12/2021
;
run;
1 ACCEPTED SOLUTION

Accepted Solutions
ed_sas_member
Meteorite | Level 14

Hi @Rentum 

Please try this:

data _null_;
	set have;
	call symputx(VarName, put(VarDate,ddmmyy10.));
run;

NB: if you want to use those macrovariables in further calculations, you should better keep the unformatted valued (even if not 'human-readable'). However, if it is for display in titles for example, formatted values are fine.

 

Best,

View solution in original post

3 REPLIES 3
ed_sas_member
Meteorite | Level 14

Hi @Rentum 

Please try this:

data _null_;
	set have;
	call symputx(VarName, put(VarDate,ddmmyy10.));
run;

NB: if you want to use those macrovariables in further calculations, you should better keep the unformatted valued (even if not 'human-readable'). However, if it is for display in titles for example, formatted values are fine.

 

Best,

Rentum
Fluorite | Level 6

OH MY GOD! it was so easy, and I had tried so many difficult things.

 

Thank you a lot, @ed_sas_member you are my hero!

 

NB: In next step I have a macro that formats those dates for further use and there I have another question about how to put the list of variables when recalling the macro, but this is off topic of this question, so I will go to look for answer in a forum. Hope I can find it 🙂

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 3 replies
  • 604 views
  • 4 likes
  • 2 in conversation