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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Removing records from SAS data set

Status
Not open for further replies.

State2000

Programmer
Jan 29, 2009
3
US
Hello,
I have a question involving removing records from a SAS dataset. This link has a made-up dataset similar to what I am working with:


There are many records and results for the months of October, November, and December. The only three sites in the dataset are the ones in the table above, and the same person can be in the set more than once for a different test.

In need to:
Remove the last 300 records from the Health Dept(the ones with the latest dates) from October, the last 300 records from November, and the last 300 from December

Remove the last 800 records from the Hospital Clinic(the ones with the latest dates) from October, the last 800 records from November, and the last 800 from December

Remove the last 600 records from the Doctor Office(the ones with the latest dates) from October, the last 600 records from November, and the last 600 from December

What code would I need to use to get SAS to do this? I would appreciate anyone who would take the time to help me out here. Thanks.
 
I would do this in a few steps.

1 - Append a sequential number to the records.
2 - Reverse the sort order.
3 - Start counting records and only output once your counter has got over your threshold.

For part 3 you want to use the RETAIN statement, and the first. and last variables in BY GROUP PROCESSING.
That should do the trick fairly simply.

Chris
Business Analyst, Code Monkey, Data Wrangler.
SAS Guru.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top