BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
hvins
Calcite | Level 5

I am attempting to write a program that will assign items a location in 5 row by 5 column boxes. The number of items will vary by the shipment, and I want the program to be able to adapt to whatever that total number of items is. 

 

Using the code below, I have been successful at assigning the proper number of boxes I will need (25 item per box, counting up the number of boxes until all items have a box assigned) however, I am having trouble with the rows and columns. Once a new box starts and the number of respective rows and columns hit 5, I need the values to start back at 1 again for the new box. What I have below just continues the numbering to 6, 7, 8, etc.

 

 

data shipping_location;
set manifest;

shipping_box = .;
shipping_row = .;
shipping_col = .;

do b = 1 to _n_;
	if shipping_box = . then do;
		if _n_ =< 81*b then shipping_box = b;

		do r = 1 to _n_;
		if shipping_row = . then do;
			if _n_ =< 9*r then shipping_row = r;

				do c = 1 to _n_; 
					if shipping_col = . then do;
						if _n_ =< c then shipping_col = c;
					
					end;
				end;
			end;
		end;
	end;
end;
run;

 

I want the output to look like this:

 

ItemBoxRow Col
A111
B112
C113
D114
E115
F121
G122
H123
I124
J125
K131
L132
M133
N134
O135
P141
Q142
R143
S144
T145
U151
V152
W153
X154
Y155
Z211
AA212
BB213
CC214
DD215
EE221
FF222
GG223
HH224
II225

 

 

Thank you! 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Please see how close this comes

 

data want;
   set have;
   col = mod(_n_-1,5)+1;
   row = mod((floor((_n_-1)/5)+1)-1,5)+1;
   box = mod( floor((_n_-1)/25 +1),25);
run;

View solution in original post

2 REPLIES 2
ballardw
Super User

Please see how close this comes

 

data want;
   set have;
   col = mod(_n_-1,5)+1;
   row = mod((floor((_n_-1)/5)+1)-1,5)+1;
   box = mod( floor((_n_-1)/25 +1),25);
run;
hashman
Ammonite | Level 13

@hvins;

Simple arithmetic:

data want ;                   
  set have ;                  
  box = ceil (_n_ / 25) ;     
  row = ceil (_n_ /  5) ;     
  col = 1 + mod (_n_ - 1,  5) ;
run ;                         

Kind regards

Paul D.

SAS Innovate 2025: Call for Content

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 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 2 replies
  • 413 views
  • 0 likes
  • 3 in conversation