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.
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.
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.
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.
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.
Thank's a lot , in firsthand tried with the intick , but it didn't worked , now i see my error.
thank's a lot
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.