Hi,
I have a dataset with date variables in numeric form, for example, 20984. I would like change it to YYYYMMDD10.
I have attempted
Data TESTDATA;
Set TESTDATA;
mortality = input (put(deathdate, 8.) YYMMDD10.);
format mortality YYMMDD10.;
run;
But it failed and provides values for example 2002-07-23 which is incorrect. The data is from year 2016 and 2017.
Any help is appreciated. Thanks!
May I ask what date 20984 represents? It may be that it is supposed to represent 14JUN2017. If so, there is no need to "convert" it to anything, and you certainly cannot convert it to have a specific format, that would be an incorrect use of the language.
All you have to do is assign the proper format to the variable.
data testdata1;
set testdata;
format deathdate yymmdd10.;
run;
or use any other date format you want.
Better yet
proc datasets library=work;
modify testdata;
format deathdate yymmdd10.;
run; quit;
and now you don't have to read every row in the entire data set just to assign a format to one variable.
May I ask what date 20984 represents? It may be that it is supposed to represent 14JUN2017. If so, there is no need to "convert" it to anything, and you certainly cannot convert it to have a specific format, that would be an incorrect use of the language.
All you have to do is assign the proper format to the variable.
data testdata1;
set testdata;
format deathdate yymmdd10.;
run;
or use any other date format you want.
Better yet
proc datasets library=work;
modify testdata;
format deathdate yymmdd10.;
run; quit;
and now you don't have to read every row in the entire data set just to assign a format to one variable.
Thank you for your response! Yes date 20984 represents 14JUN2017. I am a new user of sas. I would like to export this SAS file to SPSS. I have attempted to export into SPSS or excel where I do not get equivalent values in date format.
Your SPSS question probably belongs in a new thread with appropriate subject line. Or better yet, ask in an SPSS forum.
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.