Converting character dates to SAS date formats.

Reply
New Contributor
Posts: 2

Converting character dates to SAS date formats.

I have searched the forum, and unless I am missing something obvious I can't find the answer to this question...

I have monthly dates in the following format : 'JUL2010' and I need them to be converted to SAS dates.  They are currently formatted as character variables.  I need to get them formatted so I can work with some of the time series functions. 

I am also unsure of where to do the conversion at...Currently I am bringing the dataset in via a proc import.  Other discussions on similar topics had people creating a new dataset from the imported one.  (Sorry for the naive question, I am just getting serious about SAS programming).

Esteemed Advisor
Esteemed Advisor
Posts: 7,211

Re: Converting character dates to SAS date formats.

Use the input to convert character to a numeric format (dates/times are numeric):

data want;

  a="JUL2010";

  b=input(a,monyy7.);

  format b monyy7.;

run;

Respected Advisor
Posts: 3,775

Re: Converting character dates to SAS date formats.

data _null_;
  
x'JUL2010';
   d = input(x,
monyy7.);
   format d monyy7.;
  
put _all_;
  
run;

x=JUL2010 d=JUL2010 _ERROR_=0 _N_=1
Super Contributor
Posts: 305

Re: Converting character dates to SAS date formats.

Hello,

One solution:

data _null_;

a='JUL2010';

b=input(a,monyy7.);

put b date9.;

run;

Ask a Question
Discussion stats
  • 3 replies
  • 222 views
  • 0 likes
  • 4 in conversation