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

Hello

I have a question.

 

If the value is equal to 12 then I need to divide the qty column to the EOQ column. The result will be spreading in the requested output until the total is 12. If the value less than 12 then I will keep it as it is.

 

Input 
qtyEOQ
124
04
04
04
04
04
04
04
44
04
04
04
24
04
04
124
04
04
04
04
04
04
04

 

 

Output  
qtyEOQRequested Output
1243
043
043
043
040
040
040
040
444
040
040
040
242
040
040
1243
043
043
043
040
040
040
040

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

@hcbn  Sorry  Too late to notice your question, but whatever!!!

 

data have;
input qty	EOQ;
cards;
12	4
0	4
0	4
0	4
0	4
0	4
0	4
0	4
4	4
0	4
0	4
0	4
2	4
0	4
0	4
12	4
0	4
0	4
0	4
0	4
0	4
0	4
0	4
;
data want;
set have;
retain k q;
if qty>0 then do; q=qty;k1=0;end;
if qty=12 then  k=qty/EOQ;
k1+k;
k=ifn(q=12,(k1<=12)*k,qty);
drop k1 q;
run;

 

 

 

 

View solution in original post

6 REPLIES 6
PeterClemmensen
Tourmaline | Level 20

One way

 

data have;
input qty EOQ;
datalines;
12 4
0 4
0 4
0 4
0 4
0 4
0 4
0 4
4 4
0 4
0 4
0 4
2 4
0 4
0 4
12 4
0 4
0 4
0 4
0 4
0 4
0 4
0 4
;

data want(drop=c temp);
   set have;
   Requested_Output=qty;
   if qty>0 then Requested_Output=qty;

   if qty=12 then do;
      Requested_Output=qty/EOQ;
      temp=Requested_Output;
      c=temp;
   end;

   if qty=0 and c<12 then do;
      c=c+temp;
      Requested_Output=temp;
   end;

   retain c temp;
run;
hcbn
Obsidian | Level 7
Thank you so much. It is working. I appreciate your help 🙂
hcbn
Obsidian | Level 7

Sorry it does not correct accurately

novinosrin
Tourmaline | Level 20

@hcbn  Sorry  Too late to notice your question, but whatever!!!

 

data have;
input qty	EOQ;
cards;
12	4
0	4
0	4
0	4
0	4
0	4
0	4
0	4
4	4
0	4
0	4
0	4
2	4
0	4
0	4
12	4
0	4
0	4
0	4
0	4
0	4
0	4
0	4
;
data want;
set have;
retain k q;
if qty>0 then do; q=qty;k1=0;end;
if qty=12 then  k=qty/EOQ;
k1+k;
k=ifn(q=12,(k1<=12)*k,qty);
drop k1 q;
run;

 

 

 

 

hcbn
Obsidian | Level 7

@novinosrin

hcbn
Obsidian | Level 7
@novinosrin this is working

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 6 replies
  • 1197 views
  • 1 like
  • 3 in conversation