BookmarkSubscribeRSS Feed
stat11
Calcite | Level 5
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
1 REPLY 1
deleted_user
Not applicable
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;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1157 views
  • 0 likes
  • 2 in conversation