RenTum
RenTum

Reputation: 3

Is it possible in SAS to assign values from one column to a macro variables from another column

I have lost may 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;

Upvotes: 0

Views: 558

Answers (1)

imnotarobot
imnotarobot

Reputation: 141

It work fine. The end of log in the comment:

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;

data _null_;
    set have;
        call symput(VarName,put(VarDate,ddmmyys10.));
run;

%put &A_10.;
%put &A_11.;
.
.
.
.
/*results in the log:

4116  %put &A_10.;
14/06/2020
4117  %put &A_11.;
12/06/2020

*/

Upvotes: 1

Related Questions