BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SASGT
Calcite | Level 5

Hi, I have searched the forum for help for my problem, and I think i have an idea how to solve it, but I need some more help. I would really appreciate if someone out there could help me. I am new to SAS EG and have limited SAS programming skills. I do however have a good understanding of general code.

My data set is structured as follows:

Occurrence ID (unique)     Person ID     Date     Calculated column 1

x1                                   y1                   n1    

x2                                   y2                   n2    

x3                                   y1                   n3    

x4                                   y1                   n4    



I want to populate the calculated column according to how many days there are between two occurrences for a unique person.

For example:

For person ID = y1. Days between occurrence x3 and x1 = n3 - n1. The value will thereafter either set a 1, 2, 3 or 4 in the calculated column according to how many days there are.


My idea is to transpose the data set as follows:


Person ID (unique)     x1     x2     x3       x4    Calculated column x1     Calculated column x2 ...

y1                             n1     n2                n4       

y2                                              n3      

                                             


I can thereafter calculate by comparing columns x1,...xn for each person ID.


After this step, I need to transpose the data set back in order to have a unique calculated column values for each Occurrence ID.


Is this a good approach or do any of you have a better idea how I might attack this problem?


Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19

I don't know that you need to transpose but you will need to sort.

data person;
   input oid person:$2.  date:date9.;
  
format date date9.;
  
cards;
1 y1 27FEB2015
2 y2 27FEB2015
3 y1 01MAR2015
4 y1 05MAR2015
;;;;
   run;
proc sort data=person;
   by person date;
   run;
data persion2;
   set person;
   by person;
   dif = dif(date);
  
if first.person then call missing(dif);
   run;
proc print;
  
run;

3-2-2015 6-52-51 AM.png

View solution in original post

2 REPLIES 2
data_null__
Jade | Level 19

I don't know that you need to transpose but you will need to sort.

data person;
   input oid person:$2.  date:date9.;
  
format date date9.;
  
cards;
1 y1 27FEB2015
2 y2 27FEB2015
3 y1 01MAR2015
4 y1 05MAR2015
;;;;
   run;
proc sort data=person;
   by person date;
   run;
data persion2;
   set person;
   by person;
   dif = dif(date);
  
if first.person then call missing(dif);
   run;
proc print;
  
run;

3-2-2015 6-52-51 AM.png
SASGT
Calcite | Level 5

Thank you!

Much easier and exactly what I want to achieve.

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 2146 views
  • 0 likes
  • 2 in conversation