Help using Base SAS procedures

complex summing????

Reply
N/A
Posts: 0

complex summing????

I need to manipulate the data generated from the output that you helped with. RMS{i}=21.1 is a code associated with a negative number (i.e. - 2.75). I need to subtract that number from the codes below.

Code
21.1 = Milling (Always Subtracted)
06 = Pavement (Always Added)
08 = Pavement (Always Added)
40 = Base (Ignored except when below milling)

Senario 1
Instance Code Depth
1 21.1 -2.75
2 08 1.00 2.1=sum(1:2) -1.75
3 40 1.00 3.1=sum(2.1:3) -0.75
4 06 0.50 4.1=sum(3.1:4) -0.25
5 08 0.75 5.1=sum(4.1:5) 0.50
6 40 6.00 6.1=sum(5.1:6) 0.50
7 08 2.75 7.1=sum(6.1:7) 3.25

Output = 3.50 Total Depth
Super Contributor
Posts: 359

Re: complex summing????

Posted in reply to deleted_user
Probably something like
if code = 21.1 then depth = depth*(-1);
prior to your sum.
N/A
Posts: 0

Re: complex summing????

That would only make the 21.1 a positve number increasing the total depth. i need to deduct 21.1 from the numbers below but once the number becomes positive then stop the sum and any codes that are a base, set them equal to zero then sum the leftover numbers from where the first sum stopped.
Super Contributor
Posts: 359

Re: complex summing????

Posted in reply to deleted_user
I'm afraid that I am not following the logic you are trying to describe.
PROC Star
Posts: 1,759

Re: complex summing????

Posted in reply to deleted_user
Your explanations are very obscure indeed.
[pre]
data SAMPLE;
infile cards missover;
do until(CODE=.);
input CODE DEPTH @;
output;
end;
input;
cards;
20 1.00 45 9.00 21.1 -4.75 08 1.00 06 0.50 08 1.50
20 0.75 21.1 -2.2 08 1.50 20 0.50 21.2 -2.00 08 1.25
20 0.75 21.1 -2.25 08 1.50 21.2 -2.00 08 1.25 25 9.00
21.1 -2.75 8 1 40 1 6 .5 8 .75 40 6 8 2.75
run;

data SUMS;
set SAMPLE;
if SUM <0 then SUM+DEPTH; *add if negative;
else if CODE ne 40 then SUM+DEPTH; *else if positive add if not base;
if CODE=. then SUM=.; *reset between groups;
run;
.

yields for the last data line:
CODE DEPTH SUM
21.1 -2.75 -2.75
8.0 1.00 -1.75
40.0 1.00 -0.75
6.0 0.50 -0.25
8.0 0.75 0.50
40.0 6.00 0.50
8.0 2.75 3.25

unsure how you find 3.50
Ask a Question
Discussion stats
  • 4 replies
  • 123 views
  • 0 likes
  • 3 in conversation