Help using Base SAS procedures

DO LOOP UNIQUE START/STOP

Reply
N/A
Posts: 0

DO LOOP UNIQUE START/STOP

Could anyone point me in the right direction. I want to perfom a do loop for a range within the loop.

********************************************************;
DATA MILL ;
SET MILL1;
BY CNTY SR SEG BEG_OFF;
ARRAY DPT{29} LAY_DT1-LAY_DT29;
ARRAY PAV{29} PAV_ST1-PAV_ST29;
ARRAY RMS{29} RMS_CD1-RMS_CD29;

DEPTH=0;
CODE=0;

OFF_LEN=END_OFF-BEG_OFF;
IF LAY_CD1='BRDK' OR LAY_CD2='BRDK' THEN DELETE;

DO I=1 TO 29 BY 1 UNTIL (CODE=21.2);

IF PAV{i} NE 'W' THEN DO;
DEPTH=DPT{i}; CODE=RMS{i};
output;
END;
END;
RUN;

*******************************************************;

I am looking to have I=1 equal (CODE=21.1) so that I get the range between (CODE=21.1) and (CODE=21.2). The particular code is at different I throughout the data so i can set it I=6 to 29 BY 1 UNTIL (CODE=21.2);
Super Contributor
Super Contributor
Posts: 3,174

Re: DO LOOP UNIQUE START/STOP

Honestly, your question or problem is unclear, at least to me.

Suggest if you are having difficulty diagnosing the problem, consider adding a PUTLOG command, such as the one below at different locations (and change "nn" to some unique value for each PUTLOG occurence):

PUTLOG ">DIAG-nn> " / _ALL_;

This additional code will help you detect the different variable conditions (along with SAS maintained automatic variables like _N_) as you are processing.

Scott Barry
SBBWorks, Inc.
N/A
Posts: 0

Re: DO LOOP UNIQUE START/STOP

RMS_CD2 LAY_DT2 RMS_CD3 LAY_DT3 RMS_CD4 LAY_DT4 RMS_CD5 LAY_DT5 RMS_CD6 LAY_DT6 RMS_CD7 LAY_DT7
20 0.75 21.1 -2.25 08 1.50 21.2 -1.50 08 1.50 12 2.00

this is how the data looks. I only want the do loop to select the fields from RMS_CD3 to RMS_CD5.
Super Contributor
Posts: 359

Re: DO LOOP UNIQUE START/STOP

If I understand you right setting a start point flag should help.

flag = 0; /* Reset flag *'
IF LAY_CD1='BRDK' OR LAY_CD2='BRDK' THEN DELETE;

DO I=1 TO 29 BY 1 UNTIL (CODE=21.2);
if RMS{i}=21.1 then flag = 1;

IF PAV{i} NE 'W' and flag = 1 THEN DO; /*Starts processing after flag is set */
DEPTH=DPT{i}; CODE=RMS{i};
output;
END;
END;
N/A
Posts: 0

Re: DO LOOP UNIQUE START/STOP

Thank you very much that is exactly what i needed.
N/A
Posts: 0

Re: DO LOOP UNIQUE START/STOP

Maybe you could help me with my next problem. 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
Ask a Question
Discussion stats
  • 5 replies
  • 143 views
  • 0 likes
  • 3 in conversation