Help using Base SAS procedures

Array

Reply
Regular Contributor
Posts: 229

Array

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
Super Contributor
Posts: 345

Re: Array

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
SAS Super FREQ
Posts: 8,868

Re: Array

Posted in reply to andreas_lds
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
Ask a Question
Discussion stats
  • 2 replies
  • 119 views
  • 0 likes
  • 3 in conversation