Dataset:
Obs OT Quant Value
1 1 1 10
2 1 2 10
3 1 3 15
4 1 4 20
5 1 5 20
6 1 6 25
7 2 1 10
8 2 2 15
9 2 3 20
10 2 4 25
11 2 5 25
12 2 6 30
13 3 1 10
14 3 2 15
15 3 3 15
16 3 4 20
17 3 5 25
18 3 6 25
I'm trying to have an array that describes it like: if OT=1, Quant=1 then Value=10
data have;
input obs $ OT Quant Value ;
cards;
1 1 1 10
2 1 2 10
3 1 3 15
4 1 4 20
5 1 5 20
6 1 6 25
7 2 1 10
8 2 2 15
9 2 3 20
10 2 4 25
11 2 5 25
12 2 6 30
13 3 1 10
14 3 2 15
15 3 3 15
16 3 4 20
17 3 5 25
18 3 6 25
;
data want;
if _n_=1 then
do until(lr);
set have end=lr;
array D{3,6} ;
d(OT,quant)=value;
end;
retain d;
/*Now do your look up*/
set have;/*read your dataset and do whatever*/
/*whatever*/
run;
SAS Arrays only involve variables on one row or observation of a data set.
You probably should provide a more complete description of what you are actually needing to do. Provide input and output data set examples, preferably using data step code and pasting such into a code box opened with the forum's {I} icon.
I may also be a good idea to explain how you actually are going to use the resulting data set/array.
So your question about an array does not seem to apply to this data set, as far as I can see.
I'm trying to have an array that describes it like: if OT=1, Quant=1 then Value=10
In your data step, use:
if ot=1 and quant=1 then value=10;
No array needed.
data have;
input obs $ OT Quant Value ;
cards;
1 1 1 10
2 1 2 10
3 1 3 15
4 1 4 20
5 1 5 20
6 1 6 25
7 2 1 10
8 2 2 15
9 2 3 20
10 2 4 25
11 2 5 25
12 2 6 30
13 3 1 10
14 3 2 15
15 3 3 15
16 3 4 20
17 3 5 25
18 3 6 25
;
data want;
if _n_=1 then
do until(lr);
set have end=lr;
array D{3,6} ;
d(OT,quant)=value;
end;
retain d;
/*Now do your look up*/
set have;/*read your dataset and do whatever*/
/*whatever*/
run;
I was wondering if you could help me figure out what I could do if there are missing values (.) in the Value column?
Sure @MartSas What's your requirement?
I answered basically how do you make an array?
If you want anything bigger, no matter complex or simple, just open up a new thread specifically stating your objective. Do not hesitate or feel shy. We all have been a learner/still learning.
Anyways, what we need is
1. HAVE dataset sample
2. Your WANT dataset sample
3. An explanation of what you want to accomplish
That's all we need. If the objective is different to your subject here how do you make an array? I suggest you open up a new thread and write the above 3
SAS/IML is the right way to do this.
data have;
input obs $ OT Quant Value ;
cards;
1 1 1 10
2 1 2 10
3 1 3 15
4 1 4 20
5 1 5 20
6 1 6 25
7 2 1 10
8 2 2 15
9 2 3 20
10 2 4 25
11 2 5 25
12 2 6 30
13 3 1 10
14 3 2 15
15 3 3 15
16 3 4 20
17 3 5 25
18 3 6 25
;
proc iml;
use have;
read all var {value ot quant} into x[c=vname];
close;
z=full(x);
print z;
quit;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: