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: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 605 views
  • 0 likes
  • 2 in conversation