DATA Step, Macro, Functions and more

Converting a string into a date SAS enterprise guide

Accepted Solution Solved
Reply
New Contributor
Posts: 3
Accepted Solution

Converting a string into a date SAS enterprise guide

[ Edited ]

I have a column in a data set that has dates in a string format YYYY-MM-DD. 

 

How can I convert this into a date column? 


Accepted Solutions
Solution
‎10-19-2016 10:57 AM
Super User
Posts: 7,866

Re: Converting a string into a date SAS enterprise guide

newvar = input(oldvar,yymmdd10.);
format newvar yymmddd10.;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Solution
‎10-19-2016 10:57 AM
Super User
Posts: 7,866

Re: Converting a string into a date SAS enterprise guide

newvar = input(oldvar,yymmdd10.);
format newvar yymmddd10.;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 19,878

Re: Converting a string into a date SAS enterprise guide

[ Edited ]

The code provided should have worked so either your data isn't as specified or you did something wrong. How did you use the code provided? In a query builder or as a data step? What did your log say?

 

Verify the type and format of your variable.

 

Run a proc contents and post the results for that variable. 

 

 

data test;
length x $10.;
x="2016-10-12";
y=input(x, yymmdd10.);
format y date9.;
run;

proc print data=test;
run;

 

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 1881 views
  • 2 likes
  • 3 in conversation