BookmarkSubscribeRSS Feed
R_Win
Calcite | Level 5
Data l;
input amt number no;
cards;
78797 879 1
1215 756 2
12125 963 3
145 782 4
.
.
.
1245 712 160
254 740 161
run;

I want to pass them into macro vaiables like if No=1 then amt should
if no=1 call symput('A1',amt) ;
if no=1 call symput('B1',number);
.
.

if no=161 call symput('A161',amt) ;
if no=161 call symput('B161',number);
i want to do for all the obs as i am having many obs any one can help by using array.I wnat all these macro variables as i wnat to do multipilcation based on No.
if no=1 then amt=amt+3 and number=number+3*.30;
so i need these macro for every obs
2 REPLIES 2
andreas_lds
Jade | Level 19
You should explain why you think that creating that many macro variables is necessary. The macro-variables name can be created by appending the dataset variable "no" to the appropriate letter.
[pre]data _null_;
set yourdata;
call symput(cats('A', no), amt);
call symput(cats('B', no), number);
run;[/pre] Message was edited by: andreas_lds
Cynthia_sas
SAS Super FREQ
Hi:
I'm still not convinced that you need a macro. I agree with Andreas. There are many techniques available to achieve your stated goal: "I want all these macro variables as i want to do multiplication based on No.
if no=1 then amt=amt+3 and number=number+3*.30;"

Consider the following program, that uses a FORMAT to create a variable called MULT -- based on the variable AGE -- when AGE is 11, MULT will be 2; when AGE is 13, MULT will be 6, etc:
[pre]
proc format;
value amult 11=2
12=4
13=6
14=8
15=10
16=12;
run;

data class;
set sashelp.class;
mult = input(put(age,2.0),amult.);
newnum = height * mult;
put age= mult= newnum=;
run;
[/pre]

You probably wouldn't need a format if there was some logic behind how NO=1 turned into a multiplier of 3. But even so, making a lookup list with PROC FORMAT is easier than writing a macro program when you don't need one.

Is there other processing that you are not explaining??? The title of your post was "Array", but you jumped past arrays straight into macro variables. Having numbered macro variables is NOT the same thing as building an array and using numbered macro variables in place of an array is probably not a good idea. At this point, however, I don't understand the need for either arrays or macro variables.

cynthia

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 2 replies
  • 639 views
  • 0 likes
  • 3 in conversation