Hello Everyone,
I am trying to create a three-dimensional array from the following data:
Warehouse Locations
Product_Line | Product_Grp_ID | Product_Cat_ID | Warehouse |
21 | 0 | 0 | A2100 |
21 | 0 | 1 | A2101 |
21 | 1 | 0 | A2110 |
21 | 1 | 1 | A2111 |
21 | 2 | 0 | A2120 |
21 | 2 | 1 | A2121 |
22 | 0 | 0 | B2200 |
22 | 0 | 1 | B2201 |
22 | 1 | 0 | B2210 |
22 | 1 | 1 | B2211 |
22 | 2 | 0 | B2220 |
22 | 2 | 1 | B2221 |
So I am supposed to produce a program that is supposed to pull the warehouse number from a three-dimensional array.
This is my program so far:
data warehouse_locations (keep=Product_ID Product_Name Product_Line Product_Grp_ID Product_Cat_ID Warehouse);
drop PL PG PC;
/*set few_warehouses;*/
format Warehouse $6.;
array wrhse{21:22,0:2,0:1} (21,0,0,
21,0,1,
21,1,0,
21,1,1,
21,2,0
21,2,1,
22,0,0,
22,0,1,
22,1,0,
22,1,1,
22,2,0,
22,2,1);
Product_Line=input(substr(Prod_ID,1,2),2.); /*Using substr function to extract the number of the Product Line*/
Product_Grp_ID=substr(Prod_ID,4,1); /*Using substr function to extract the number of the Group_ID*/
Product_Cat_ID=substr(Prod_ID,12,1); /*Using substr function to extract the Catalog ID*/
PL=Product_Line; /*Setting temp variable PL to Product_Line*/
PG=Product_Grp_ID;
PC=Product_Cat_ID; /*Setting temp variable PC to Product_Cat_ID*/
do until(last.warehouse);
set few_warehouses;
by warehouse;
Warehouse=wrhse{PL,PG,PC};
end;
run;
In the log, I get the following message:
WARNING: Too many values for initialization of the array wrhse. Excess values are ignored.
However, my data does run, but it does not pull the warehouse numbers like I need.
Could someone look at my code and let me know what is wrong with it?
Thanks,
Alisa
array wrhse{21:22,0:2,0:1}
The second dimension is not right.From your code, It should has six member,not three.
By the way. what result do you want ? why you have to use array?
Ksharp
If you simply want to look up a warehouse code based on the three keys then a much easier approach would be something like this:
proc format;
value $lookup_warehouse
'2100' = 'A2100'
'2101' = 'A2101'
add rest of keys here...
;
run;
data _null_;
Prod_ID = '21X0XXXXXXX0';
warehouse = put(substr(Prod_ID, 1,2) !! substr(Prod_ID, 4,1) !! substr(Prod_ID,12,1), $lookup_warehouse.);
put _all_;
run;
What I am trying to get is:
Product_ Product_ Product_
Obs Product_ID Product_Name Line Grp_ID Cat_ID Warehouse
1 210000000000 Children 21 0 0 A2100
2 210100000000 Children Outdoors 21 1 0 A2110
3 210100100000 Outdoor things, Kids 21 1 0 A2110
4 210200000000 Children Sports 21 2 0 A2120
5 210200100000 A-Team, Kids 21 2 0 A2120
I have to use an array because it is a part of the assignment. Should I switch the middle part of my array from 0:2, 0:1 to 0:1, 0:2?
Thanks,
Alisa
try changing
array wrhse{21:22,0:2,0:1}
to
array wrhse{21:22,0:5,0:1}
Hi Linlin,
Unfortunately, this did not work either.
Thanks,
Alisa
try this one:
data few_warehouses;
input Prod_ID $ 1-13 Product_Name $15-34 ;
cards;
210000000000 Children
210100000000 Children Outdoors
210100100000 Outdoor things, Kids
210200000000 Children Sports
210200100000 A-Team, Kids
220000000000 Children
220100000000 Children Outdoors
220100100000 Outdoor things, Kids
220200000000 Children Sports
220200100000 A-Team, Kids
;
proc print;run;
data warehouse_locations (keep=Prod_ID Product_Name Product_Line Product_Grp_ID Product_Cat_ID Warehouse);
drop PL PG PC;
set few_warehouses;
format Warehouse $6.;
array wrhse {21:22,0:2,0:1} $ _temporary_ ("A2100" "A2101" "A2110" "A2111" "A2120" "A2121" "B2200" "B2201" "B2210" "B2211" "B2220" "B2221");
Product_Line=input(substr(Prod_ID,1,2),2.); /*Using substr function to extract the number of the Product Line*/
Product_Grp_ID=substr(Prod_ID,4,1); /*Using substr function to extract the number of the Group_ID*/
Product_Cat_ID=substr(Prod_ID,12,1); /*Using substr function to extract the Catalog ID*/
PL=Product_Line; /*Setting temp variable PL to Product_Line*/
PG=Product_Grp_ID;
PC=Product_Cat_ID; /*Setting temp variable PC to Product_Cat_ID*/
Warehouse=wrhse{PL,PG,PC};
run;
proc print;run;
Product_ Product_ Product_
Obs Prod_ID Product_Name Warehouse Line Grp_ID Cat_ID
1 210000000000 Children A2100 21 0 0
2 210100000000 Children Outdoors A2110 21 1 0
3 210100100000 Outdoor things, Kids A2110 21 1 0
4 210200000000 Children Sports A2120 21 2 0
5 210200100000 A-Team, Kids A2120 21 2 0
6 220000000000 Children B2200 22 0 0
7 220100000000 Children Outdoors B2210 22 1 0
8 220100100000 Outdoor things, Kids B2210 22 1 0
9 220200000000 Children Sports B2220 22 2 0
10 220200100000 A-Team, Kids B2220 22 2 0
Linlin
Have you tried removing the commas from the section where you assign values in the array?
i.e:
array wrhse{21:22,0:2,0:1} (2100
2101
2110
2111
2120
2121
2200
2201
2210
2211
2220
2221);
Don't know if that'll work, but I could see how the former would suggest more values than the dimensions of your array allow.
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.