DATA Step, Macro, Functions and more

how to convert date $8. to sas date

Reply
Super Contributor
Posts: 345

how to convert date $8. to sas date

the original dataset has date variables are listed as 20051001, 20160705

would you please recommend how to convert them to sas date

 

FORMAT date date9.;
date= input(date, yymmdd10.);
Super User
Posts: 19,855

Re: how to convert date $8. to sas date

You can't change a variable type in place, you need to recreate a new variable.

 

FORMAT date_new date9.;
date_new= input(date, yymmdd10.);
Super Contributor
Posts: 345

Re: how to convert date $8. to sas date

sorry, my previous message was not clear

i did the same way as you said,

 

with a new variable

but the new varabile has all missing values

 

the date format is yyyymmdd, like 20160705, i do not know how to convert

Super User
Posts: 7,834

Re: how to convert date $8. to sas date

Use the yymmdd8. format in the input function.

Also post the log of the data step.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 19,855

Re: how to convert date $8. to sas date

Was there an error or note in your log?

Super Contributor
Posts: 345

Re: how to convert date $8. to sas date

thanks.

there was no error

the problem disappeared when i ran my code again (eighter 8 or 10), so it might  the sas or my computer problem?

Super User
Posts: 19,855

Re: how to convert date $8. to sas date

Possibly. It's more likely you had some other issue and running from the beginning fixed it. 

This is especially true if your in the habit of naming your output the same at the dataset in your SET statement. 

 

Data want;
Set want;

...

Run;
Super Contributor
Posts: 345

Re: how to convert date $8. to sas date

thanks

Ask a Question
Discussion stats
  • 7 replies
  • 454 views
  • 3 likes
  • 3 in conversation