BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ashishj816
Quartz | Level 8

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

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
data want;
  dt="2003-01";
  actual=input(dt,anydtdte.);
  format actual monyy7.;
run;

View solution in original post

4 REPLIES 4
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;
Loko
Barite | Level 11

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
;
Ksharp
Super User
data want;
  dt="2003-01";
  actual=input(dt,anydtdte.);
  format actual monyy7.;
run;
ashishj816
Quartz | Level 8

This is also working for me thanks.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 2394 views
  • 7 likes
  • 4 in conversation