Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Do Until Loop

Status
Not open for further replies.

melfb

MIS
Dec 17, 2002
3
GB
I have read in a report using the input statment to create a SAS dataset. Unfortuantely, the original report contains summary after each section resulting in unwanted observations.

I need to delete these additonal unwanted observations and can see that the rows that need deleting are those after a observation in which field#10 ='Summary' until the observation where field#5='End'. (this can be a variable number of records).

I have tried using the following code:

data Output ;
set InputDataset ;

if field#10='Summary then
do until (field#5='end') ;
delete ;
end ;

run ;

This only deletes the records that contain 'Summary' in Field#10 rather than all records between 'Summary' and 'end'.

Any help would be appreciated,
melfb
 
Melfb,
The code do-until statement will not work (as you clearly wrote).
Try this:

data Output ;
set InputDataset ;
retain inc_ctr 0;

if trim(field10) eq 'summary' then do;
inc_ctr=1;
end;
is_sum = inc_ctr;

if trim(field5) EQ 'end' then do;
inc_ctr=0;
end;
if is_sum then delete;
run;

What you are doing is flagging the obs that are between the summary and end records. Then you can ask the data step to ignore (delete) the records.
I hope that this has helped you...enjoy..
Klaz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top