BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
WishShahid
Calcite | Level 5

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!

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
WishShahid
Calcite | Level 5

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.

PaigeMiller
Diamond | Level 26

Your SPSS question probably belongs in a new thread with appropriate subject line. Or better yet, ask in an SPSS forum.

--
Paige Miller

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 3 replies
  • 682 views
  • 0 likes
  • 2 in conversation