Hello Everyone,
I am trying to use a two-dimensional array for a particular homework problem.
The data set orion.msp contains the average manufacturer’s suggested retail price for shoes, based on the product line and the product category. The product group ID is the last two digits of ProdCatID.
Listing of orion.msp
Prod_ Prod Avg_Suggested_
Obs Line CatID Retail_Price
1 21 2101 .
2 21 2102 70.79
3 22 2201 173.79
4 22 2202 174.40
5 23 2301 .
6 23 2302 .
7 24 2401 29.63
8 24 2402 287.80
The data set orion.shoesales contains the ProductID, the ProductName, and the TotalRetailPrice for all of the shoes sold by Orion Star.
Partial Listing of orion.shoesales
Total_Retail_
Product_ID Product_Name Price
220200200024 Pro Fit Gel Gt 2030 Women's Running Shoes $178.50
220200100092 Big Guy Men's Air Terra Sebec Shoes $83.00
240200100043 Bretagne Performance Tg Men's Golf Shoes L. $282.40
220100700024 Armadillo Road Dmx Women's Running Shoes $99.70
220200300157 Hardcore Men's Street Shoes Large $220.20
240200100051 Bretagne Stabilites 2000 Goretex Shoes $420.90
220200100035 Big Guy Men's Air Deschutz Viii Shoes $125.20
220200100090 Big Guy Men's Air Terra Reach Shoes $177.20
220200200018 Lulu Men's Street Shoes $132.80
240200100052 Bretagne Stabilities Tg Men's Golf Shoes $99.70
I tried to do the following :
data Q9;
if _n_=1 then
do until(lr);
set orion.msp end=lr;
PK = input(substr(ProductID,3,2),2.);
array D{21:24, 01:02};
D(ProdLine, PK) = AvgSuggestedRetailPrice;
end; retain D;
set orion.shoesales;
PL= input(substr(ProductID,1,2),2.);
PC= input(substr(ProductID,3,2),2.);
MSP= D{PL, PC};
run;
proc sql;
title 'combine Data Set';
select MSP 'Manufacturer Suggested Price' format=COMMA10.2, ProductID, ProductName, TotalRetailPrice
from work.Q9;
run;
However, I keep on getting the error message that the array subscript is out of range. I don't know what to do..
Any help would be appreciated!
Eventually I would need to get a table that would look like this:
Suggested Price ProductID ProductName Price
$174.40 220200200024 Pro Fit Gel Gt 2030 Women's Running Shoes $178.50
$174.40 220200100092 Big Guy Men's Air Terra Sebec Shoes $83.00
$287.80 240200100043 Bretagne Performance Tg Men's Golf Shoes L. $282.40
$173.79 220100700024 Armadillo Road Dmx Women's Running Shoes $99.70
$174.40 220200300157 Hardcore Men's Street Shoes Large $220.20
The log gives you all the information you will need. You just need to read it. Here's what to look for.
There are two spots in which you refer to the array: loading elements into it, and retrieving elements from it. The log will tell you which statement encountered the subscript out of range.
Once you have that, the log will also tell you the values of all variables on that observation. It should be easy to see which of the subscript variables are out of range.
At that point, it might be clear as day or you might have to do a little digging into the data, to figure out why the subscripts take on those values.
The log gives you all the information you will need. You just need to read it. Here's what to look for.
There are two spots in which you refer to the array: loading elements into it, and retrieving elements from it. The log will tell you which statement encountered the subscript out of range.
Once you have that, the log will also tell you the values of all variables on that observation. It should be easy to see which of the subscript variables are out of range.
At that point, it might be clear as day or you might have to do a little digging into the data, to figure out why the subscripts take on those values.
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 the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: