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

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 4 replies
  • 861 views
  • 5 likes
  • 4 in conversation