Desktop productivity for business analysts and programmers

Convert character/string to date9.

New Contributor
Posts: 3

Convert character/string to date9.



Somehow my dates were input into my dataset wrong and I need to change them.


I have the dates as a string right now and they are in yyq6. format but in characters. So the current dates show 2017Q1, 2017Q2, etc. but are char$6 as a string.


What I want is to see 01JAN2017 for the string 2017Q1, 01APR2017 for the string 2017Q2 and so on. But not just a string of that - it needs to be a proper date format.


I feel like I have tried everything and at best it will error out and at worst it will set all of values for that variable to missing.


How can I do this??


Thank you for your help!!

Super User
Posts: 10,571

Re: Convert character/string to date9.

Use the YYQ informat:

numvar = input(charvar,yyq6.);
format numvar date9.;
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Ask a Question
Discussion stats
  • 1 reply
  • 2 in conversation