DATA Step, Macro, Functions and more

Two-dimensional Array for Table Lookup

Reply
Occasional Contributor
Posts: 12

Two-dimensional Array for Table Lookup

Hi,

I need to use a two-dimensional array to perform a table lookup.

I have a text file that looks like this (the dots represent continuous data, I didn't want to type out all 630 observations):

WT A B...I
1 17.00 18.25 ... 21.65
2 22.50 19.75 ... 22.85
. . .
. . .
. . .
69 28.95 31.80 ... 36.25
70 32.60 34.95 ... 37.05

I have a dataset with entries having the variables WT and Group (A-I). I would like a code that will give me the price, based on the WT and Group of an item. So for an item that weighed 2 and was in group B, 19.75 would be outputed.

I tried doing something like this, but couldn't get it to work.

FILENAME RATES 'F:\Rate.txt';
DATA LOOK_UP;
ARRAY Price{70,9};
infile RATES;
do WT = 1 to 70;
do Group = 1 to 9;
input Price{WT,Group} @;
end;
end;
set PCDTX2;
Group = input(translate(GROUP,'12345689','ABCDEFGHI'),1.);
Revenue= Price{WT,Group};
RUN;


Any help would be appreciated. Thank you.

Message was edited by: stat11 Message was edited by: stat11
N/A
Posts: 0

Re: Two-dimensional Array for Table Lookup

I would use 2 arrays to hold the values of the dataset. One array with one dimension that would keep the WT values (a row) and that would be used to load another array having two dimensions: one for WT and one for Group.


Data look_up2;
Array price{70,9};

Do i=1 to 70;

Array wt_row[*} A--I;
Do j=1 to dim(wt_row);
price{wt, j}=wt_row{j};
End;
End;

Run;
Ask a Question
Discussion stats
  • 1 reply
  • 189 views
  • 0 likes
  • 2 in conversation