BookmarkSubscribeRSS Feed
Walternate
Obsidian | Level 7

I have a dataset composed of a number of events. Each row represents one event for one person as follows:

ID       Event         Eventdate

a         xyz            04/2012

b         xyz            05/2013

a         efg             08/2012

b         xyz            09/2012

What I'd like to do is look at a person's sequence of events. I was thinking I would transpose the data like this:

proc transpose data=data out=new;

by id;

id event;

var eventdate;

run;

That way, each person will have a sequence of dates and I will know which event is which. My question is what will happen if the same person has the same event twice, and if there's a way to tweak my code to avoid losing data.

I'm also open to suggestions on non-proc transpose ways to establish a sequence of events for each person.

Help is much appreciated.

2 REPLIES 2
ballardw
Super User

What are you going to look at later?

You may want to start by simple sorting by id and eventdate at first. It will be significantly easier to find event x immediately preceded by event y or time between event x than trying to search across a single row.

With a transpose approach you may end up with a larger than expected number of variables when some people have large numbers of events.

Jagadishkatam
Amethyst | Level 16

Hi, Hope this helps

data have;

    input id$ event$ eventdate$;

cards;

a         xyz            04/2012

b         xyz            05/2013

a         efg            08/2012

b         xyz            09/2012

;

run;

proc sort data=have;

    by id event;

run;

data have_;

    set have;

    retain seq;

    by id event;

    if first.event then seq=1;

    else seq+1;

run;

proc sort data=have_;

    by id seq;

run;

proc transpose data=have_ out=trans_data(drop=seq _name_);

    by id seq;

    id event;

    var eventdate;

run;

Thanks,

Jagadish

Thanks,
Jag

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 3234 views
  • 0 likes
  • 3 in conversation