HI,
I am looking to create a new column with max date. That mean my new column 'max_date should have 27jul2012 for all the caseid?
data have;
input caseid $ myDate date9.;
format myDate date9.;
datalines;
34 27jul2010
35 27jul2011
37 27jul2012
;
run;
Thanks in advance.
Output:
caseid | myDate | maxDate |
34 | 27-Jul-10 | 27-Jul-12 |
35 | 27-Jul-11 | 27-Jul-12 |
37 | 27-Jul-12 | 27-Jul-12 |
Try this:
Proc sql;
Create table want as
Select *, max(myDate) as maxDate format date9.
from have
;Quit;
Output:
caseid | myDate | maxDate |
34 | 27-Jul-10 | 27-Jul-10 |
35 | 27-Jul-11 | 27-Jul-11 |
37 | 27-Jul-12 | 27-Jul-12 |
Proc sql;
Create table want as select *, max(mydate) as max_date format=date. from have;
Quit;
Output:
caseid | myDate | maxDate |
34 | 27-Jul-10 | 27-Jul-12 |
35 | 27-Jul-11 | 27-Jul-12 |
37 | 27-Jul-12 | 27-Jul-12 |
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.