BookmarkSubscribeRSS Feed
weweaw
Obsidian | Level 7

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!

5 REPLIES 5
PhilC
Rhodochrosite | Level 12
Quentin
Super User

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

BASUG is hosting free webinars Next up: Mark Keintz presenting History Carried Forward, Future Carried Back: Mixing Time Series of Differing Frequencies on May 8. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
weweaw
Obsidian | Level 7

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

orderVar_1Var_2Var_3Var_4Var_n
10266
423464
72563
8276

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. 

Astounding
PROC Star

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.

ballardw
Super User

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

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 5 replies
  • 2111 views
  • 1 like
  • 5 in conversation