Contributor
Posts: 21

# Have a my %let = a value of a variable

Hello,

I need help.  I want a %let statement to equal a variable's value.  If variable order had values of 1-10, I want %let x = order to resolve to the value of order, if the line had 5 for order I want x to be 5, currently for everything I've tried it always resolves to the variable name.

Thanks!

Regular Contributor
Posts: 194

PROC Star
Posts: 1,460

## Re: Have a my %let = a value of a variable

Hi,

CALL SYMPUTX can be used to write the value of a data step variable to a macro variable, e.g:

```60   data _null_;
61     order=5;
62     call symputx('x',order);
63   run;
64
65   %put &x;
5

```
Contributor
Posts: 21

## Re: Have a my %let = a value of a variable

I'm sorry, I meant I have a variable which is numeric, and I want when the let expression is call for that value to come up, it could be several different numbers. Say my data set looks like this

 order Var_1 Var_2 Var_3 Var_4 Var_n 1 0 2 6 6 4 2 34 6 4 7 2 5 6 3 8 2 7 6 3

I want to sum certain variables that are Var_n.  I want to start the sum with the Var_n that is the value of order.

Super User
Posts: 6,781

## Re: Have a my %let = a value of a variable

If I understand the question, you have a program that should not be using macro language at all, not even %let statements.

Is this the meaning of your question?  On the first observation, order=1.  Therefore, get the sum of Var_1 through Var_n.   Similarly, on the second observation, order=4.  Therefore, get the sum of Var_4 through Var_n.

If you are looking for something different than what I described, you will have to clarify your objective.

Good luck.

Super User
Posts: 13,563

## Re: Have a my %let = a value of a variable

I think you may be looking for an array solution:

Array v var_1 - var_n;

tot=0;

do I = order to dim(v);

tot = tot + v;

end;

Assuming 1) order is a positive integer 2) order is never larger than the number of variables

Discussion stats
• 5 replies
• 286 views
• 1 like
• 5 in conversation