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

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

1 ACCEPTED SOLUTION

Accepted Solutions
Steelers_In_DC
Barite | Level 11

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;

View solution in original post

4 REPLIES 4
Kurt_Bremser
Super User

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?

jiangmi
Calcite | Level 5

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

;

Steelers_In_DC
Barite | Level 11

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;

jiangmi
Calcite | Level 5

thanks.

I worked it out in a similar fashin.

DATA _NULL_;

SET have;

CALL SYMPUT(target, feed);

RUN;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 3347 views
  • 1 like
  • 3 in conversation