Help using Base SAS procedures

changing character to date format

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 14
Accepted Solution

changing character to date format

I have date in character format and i want to convert it into date format

 

Ex:-

 

date(In character)

2003-01

2006-11

2016-02

 

this is year and then month

 

i want to convert in date format like

 

date(In Date format)

Jan2003

Nov-2006

Feb2016


Accepted Solutions
Solution
‎05-18-2016 01:17 AM
Super User
Posts: 10,023

Re: changing character to date format

Posted in reply to ashishj816
data want;
  dt="2003-01";
  actual=input(dt,anydtdte.);
  format actual monyy7.;
run;

View solution in original post


All Replies
Super User
Super User
Posts: 7,942

Re: changing character to date format

Posted in reply to ashishj816

You can't directly.  SAS only treats full and valid dates as date values.  So what you need to do is to padd out what you have with day, then apply a format which only displays MM-YYYY - even though behind the scenes the date is complete:

data want;
  dt="2003-01";
  actual=input(cats(dt,"-01"),yymmdd10.);
  format actual mmyy8.;
run;
Super Contributor
Posts: 308

Re: changing character to date format

Posted in reply to ashishj816

hello,

data have;
infile datalines;
input a $7.;
a=compress(a,'-');
b=input(a,yymmn6.);
format b monyy7.;
datalines;
2003-01
2006-11
2016-02
;
Solution
‎05-18-2016 01:17 AM
Super User
Posts: 10,023

Re: changing character to date format

Posted in reply to ashishj816
data want;
  dt="2003-01";
  actual=input(dt,anydtdte.);
  format actual monyy7.;
run;
Occasional Contributor
Posts: 14

Re: changing character to date format

This is also working for me thanks.

☑ This topic is solved.

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

Discussion stats
  • 4 replies
  • 569 views
  • 6 likes
  • 4 in conversation