Putting a count based on Grouping

Reply
Occasional Contributor
Posts: 11

Putting a count based on Grouping

I have this data set that I would like to put a counter based on the different location of the patient goes to during a visit.

Here is an example of the dataset and ID is the counter that I am trying to place but the counter is not doing what I wanted at the moment

VisitCheck In DateTimeLocationSubLocationID
1237/2/2014 14:00EmergencyRoom 21
1237/2/2014 15:00EmergencyRoom 101
1237/2/2014 18:00SurgeryRoom32
1237/2/2014 18:30SurgeryRoom 42
1237/2/2014 18:30BedRoom 1233


Basically this is one visit, at different locations that's when I want the ID to increment by 1.

The purpose of this is at certain locations I take the first location the patient went to during the visit and certain locations I would use the second location patient went to for the visit. Additionally it allows me order the patient's location history.

Grand Advisor
Posts: 17,327

Re: Putting a count based on Grouping

If you can assume your data is sorted by patient/date/location you can use the following. The key is the notsorted option on the by statement.

data want;

set have;

by visit location NOTSORTED;

retain id;

if first.visit then id=0;

if first.location then id+1;

run;

Ask a Question
Discussion stats
  • 1 reply
  • 127 views
  • 0 likes
  • 2 in conversation