BookmarkSubscribeRSS Feed
VD
Calcite | Level 5 VD
Calcite | Level 5

Hello,

I have a character variable (DateVar) which I want to convert to date.

data have;

DateVar='November 2014';

run;

The output dataset should also show the value of DateVar as November 2014 but as a date variable.

Any suggestions?

Thanks.

4 REPLIES 4
Kurt_Bremser
Super User

I'd split the string with SCAN and then use the FINDW function to determine the month out of a reference string.

I doubt that a single format could be made that handles the display in one step. You may have to create a separate character variable for display (or keep the original column).

Steelers_In_DC
Barite | Level 11

If you need the display to look like this I would keep this column as your display, you can use substr() to cut up the format and then go with the MONYY. format for any calculations that need done.

Steelers_In_DC
Barite | Level 11

data have;

DateVar='November 2014';

run;

data prep;

set have;

month = substr(datevar,1,3);

year = scan(datevar,2,' ');

run;

data want;

format new_date monyy7.;

set prep;

new_date = input(put(trim(month)||trim(year),$char7.),monyy7.);

run;

VD
Calcite | Level 5 VD
Calcite | Level 5

Thank you, all.

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
  • 1099 views
  • 3 likes
  • 3 in conversation