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

Hello Everyone , I have this Table :

 

 

User_ID Acqu_Date
2365 17May2008
2365 18Jun2009
2365 20Gan210
2365 01-feb-12
2545 24-gen-03
2545 02-feb-04
2545 03-apr-06
2545 12Sep2010

 

And , for each user , i want to count the number of days that elapsed between the first year and the second year , e.i , for user one i want to count how many days elapsed from 17May2008 to 01Feb2012 and for the second user i want to know how many days elapsed from 24Gen2003 to 12Sep2010 .

Any Help Would Be Much Appeciated , Thank you.

1 ACCEPTED SOLUTION

Accepted Solutions
hashman
Ammonite | Level 13

@Midi:

 If you want to get just 1 row per distinct ID with ID and the number of elapsed days in your output:

data have ;                                                 
  input id date :date. ;                                    
  format date yymmdd10. ;                                   
  cards ;                                                   
2365  17May2008                                             
2365  18Jun2009                                             
2365  20jan2010                                             
2365  01-feb-12                                             
2545  24-jan-03                                             
2545  02-feb-04                                             
2545  03-apr-06                                             
2545  12sep2010                                             
;                                                           
run ;                                                       
                                                            
proc sql ;                                                  
  create table want as                                      
  select ID, intck ("day", min (date), max (date)) as elapsed
  from   have                                               
  group  id                                                 
  ;                                                         
quit ;                                                      

If you want the result from above to get merged with the original data by ID, replace the ID in the SELECT clause with an asterisk *.

 

Kind regards

Paul D. 

  

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26
proc summary data=have nway;
    class user_Id;
    var acqu_date;
    output out=want range=days_elapsed;
run;

This assumes that acqu_date are true SAS date values, not date/time values or character strings. 

--
Paige Miller
ballardw
Super User

First step: Make sure that you have SAS date values.

Second step: clean up some of those dates.

 

The values you show, in mixed formats and a month of "Gan", with apparent year of "210" or "20210", very problematic, or "gen" make me strongly suspect your data is text.

hashman
Ammonite | Level 13

@Midi:

 If you want to get just 1 row per distinct ID with ID and the number of elapsed days in your output:

data have ;                                                 
  input id date :date. ;                                    
  format date yymmdd10. ;                                   
  cards ;                                                   
2365  17May2008                                             
2365  18Jun2009                                             
2365  20jan2010                                             
2365  01-feb-12                                             
2545  24-jan-03                                             
2545  02-feb-04                                             
2545  03-apr-06                                             
2545  12sep2010                                             
;                                                           
run ;                                                       
                                                            
proc sql ;                                                  
  create table want as                                      
  select ID, intck ("day", min (date), max (date)) as elapsed
  from   have                                               
  group  id                                                 
  ;                                                         
quit ;                                                      

If you want the result from above to get merged with the original data by ID, replace the ID in the SELECT clause with an asterisk *.

 

Kind regards

Paul D. 

  

Midi
Obsidian | Level 7

Thank's a lot , in firsthand tried with the intick , but it didn't worked , now i see my error.

thank's a lot

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 4 replies
  • 656 views
  • 5 likes
  • 4 in conversation