BookmarkSubscribeRSS Feed
Walternate
Obsidian | Level 7

Hi everyone,

I have a pretty complex dataset  that looks like this:

ID      Date1        Event1        Date2      Event2    

1       4/5/13          a             7/4/13          r              

2       5/12/13        b             8/5/13          x                  

1       4/5/13          a            10/9/13         g           

3       7/7/12          a             5/5/13         m           

2      12/5/11          c            9/5/13          r             

Basically, each time a person experiences Event1 (corresponding to Date1), it generates a row. A person can experience multiple Event1s and thus generate multiple rows (eg ID 2 in the above example). The row also includes the date and type of event2 for that person. If a person has more than one Event2, it will generate another row for each Event1 (eg ID 1 in the example above).

What I want is to transpose this dataset so that it looks like this:

ID      Date1        Event1        DateR      DateX        DateG     DateM        

1       4/5/13          a             7/4/13          --            10/9/13       --                 

2       5/12/13        b             9/5/13        8/5/13          --             --                                 

3       7/7/12          a                --              --               --          5/5/13                 

2      12/5/11          c            9/5/13        8/5/13           --              --                       

The ultimate goal is to know how many people experienced events of each kind, and how long after the initial event. The problem is that if I transpose using the original Event2 variable as

the id variable, there are repeats and I'm not sure if/how that will work.

Any help is much appreciated!

1 REPLY 1
PGStats
Opal | Level 21

So, what do you want to happen with those repeats. Your expected data structure doesn't allow repeats. Do you want to keep only the first occurrence of a given type, or only the last, or something else?

PG

PG

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 949 views
  • 0 likes
  • 2 in conversation