DATA Step, Macro, Functions and more

Convert date character $CHAR6. to date DATE9.

Accepted Solution Solved
Reply
Contributor
Posts: 39
Accepted Solution

Convert date character $CHAR6. to date DATE9.

I need to convert date character $CHAR6. to date DATE9.

for example EDATE is a var I have, FDATE is a var I want:

$CHAR6.    DATE9.

 EDATE      FDATE

 201001      01JAN2010

 201612      01DEC2016

 201306      01JUN2013


Accepted Solutions
Solution
‎02-03-2017 05:12 PM
Super User
Posts: 6,928

Re: Convert date character $CHAR6. to date DATE9.

fdate = input(trim(edate)!!'01,yymmdd8.);
format fdate date9.;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Trusted Advisor
Posts: 1,353

Re: Convert date character $CHAR6. to date DATE9.

Use code:

 

Fdate = put(input(Edate||'01',yymmdd8.),date9.);

Contributor
Posts: 39

Re: Convert date character $CHAR6. to date DATE9.

thank you Shmuel that works, but var Fdate finished like type character6, I need not only format DATE9. too the var I need same type

Trusted Advisor
Posts: 1,353

Re: Convert date character $CHAR6. to date DATE9.

Your post didn't ask for numeric date.

Anyhow, see @KurtBremser solution, it fits your request.

Solution
‎02-03-2017 05:12 PM
Super User
Posts: 6,928

Re: Convert date character $CHAR6. to date DATE9.

fdate = input(trim(edate)!!'01,yymmdd8.);
format fdate date9.;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Valued Guide
Posts: 2,174

Re: Convert date character $CHAR6. to date DATE9.

Have you tried the format hunter?

See the 2014 SAS Global Forum paper 1744-2014
VFORMAT Lets SAS® Do the Format Searching

It will hunt for informats too

Peter
☑ This topic is SOLVED.

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

Discussion stats
  • 5 replies
  • 188 views
  • 1 like
  • 4 in conversation