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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 1 reply
  • 996 views
  • 0 likes
  • 2 in conversation