BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
MartSas
Fluorite | Level 6

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

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
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;

 

View solution in original post

6 REPLIES 6
ballardw
Super User

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.

 

PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
novinosrin
Tourmaline | Level 20
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;

 

MartSas
Fluorite | Level 6

I was wondering if you could help me figure out what I could do if there are missing values (.) in the Value column?

novinosrin
Tourmaline | Level 20

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

Ksharp
Super User

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;

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!

How to Concatenate Values

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.

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