Hi, All,
I ran into a situation that I have to assign multiple values to multiple macro variables like the following:
%let V0 = var_4;
%let V1 = var_5;
%let V2 = var_6;
%let V3 = var_8;
%let V4 = var_9;
%let V5 = var_10;
%let V6 = var_13;
%let V7 = var_15;
My question is: Is there anyway we can simplify this process to pair up macro values to macro variables, instead of writing 8 %let statements?
Thanks.
Joe
Not sure if this will suit your purpose but I use this for passwords, depending on how the data is used and how often it changes this might not be a good solution:
data LIB.FILE;
infile cards;
informat pw $13.;
input var1 $ var2 $;
cards;
V0 VAR_4
V1 VAR_5
V2 VAR_6
;
run;
data _null_;set LIB.FILE;
if var1 = 'V0' then call symputx('VAR4',var2);
if var1 = 'V1' then call symputx('VAR5',var2);
if var1 = 'V2' then call symputx('VAR6',var2);
run;
To automate code like this, you either need a rule for (macro variable number = var_ number), or you need a table (dataset) that contains the relationship.
Is there any way that you can state the relationship in a formula?
There is no formula for the relationship. Different variables (var_ ) are picked for different runs to feed the V0-V7, which were used in a following macro.
What I can do it to put them together in a data set like this:
data have;
input target$ feed$;
cards;
V0 var_4
V1 var_5
V2 var_6
V3 var_8
V4 var_9
V5 var_10
V6 var_13
V7 var_15
;
Not sure if this will suit your purpose but I use this for passwords, depending on how the data is used and how often it changes this might not be a good solution:
data LIB.FILE;
infile cards;
informat pw $13.;
input var1 $ var2 $;
cards;
V0 VAR_4
V1 VAR_5
V2 VAR_6
;
run;
data _null_;set LIB.FILE;
if var1 = 'V0' then call symputx('VAR4',var2);
if var1 = 'V1' then call symputx('VAR5',var2);
if var1 = 'V2' then call symputx('VAR6',var2);
run;
thanks.
I worked it out in a similar fashin.
DATA _NULL_;
SET have;
CALL SYMPUT(target, feed);
RUN;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.