DATA Step, Macro, Functions and more

how to convert 12december2015 to sas date value?

Accepted Solution Solved
Reply
Contributor dpa
Contributor
Posts: 35
Accepted Solution

how to convert 12december2015 to sas date value?

Please can anyone guide me how to do it apart from stripging the value to ddmmmyyyy format?


Accepted Solutions
Solution
‎11-03-2016 05:03 AM
Super Contributor
Posts: 305

Re: how to convert 12december2015 to sas date value?

I don't know if there is an informat which can read the value, but you can adapt it so ANYDTDTE can read it.

 

data _null_;
x='12december2015';
y=compress(x,,'d')||' '||substr(x,1,2)||', '||scan(x,-1,,'ab');

z=input(y,ANYDTDTE21.);

put z date9.;
run;

View solution in original post


All Replies
Solution
‎11-03-2016 05:03 AM
Super Contributor
Posts: 305

Re: how to convert 12december2015 to sas date value?

I don't know if there is an informat which can read the value, but you can adapt it so ANYDTDTE can read it.

 

data _null_;
x='12december2015';
y=compress(x,,'d')||' '||substr(x,1,2)||', '||scan(x,-1,,'ab');

z=input(y,ANYDTDTE21.);

put z date9.;
run;
Contributor dpa
Contributor
Posts: 35

Re: how to convert 12december2015 to sas date value?

Please can you explain 'ab' in scan function?

Super Contributor
Posts: 305

Re: how to convert 12december2015 to sas date value?

Hello,

 

you can check here the modifiers role within scan function.

http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000214639.htm

 

Super User
Super User
Posts: 7,392

Re: how to convert 12december2015 to sas date value?

Another method:

data want;
  x='12december2016';
  thedate=input(cat(substr(x,1,2),upcase(substr(x,3,3)),substr(x,11,4)),date9.);
  format thedate date9.;
run;
Contributor dpa
Contributor
Posts: 35

Re: how to convert 12december2015 to sas date value?

Thank you for your time and answer but only problem with this is  you have to change length for year extraction for diffrent month

Super User
Super User
Posts: 7,392

Re: how to convert 12december2015 to sas date value?

Yes, sorry, didn't think of that, here is an update to catch this:

data want;
  x='12december2016';
  thedate=input(cat(substr(x,1,2),upcase(substr(x,3,3)),substr(x,lengthn(x)-3,4)),date9.);
  format thedate date9.;
run;
Super User
Posts: 9,671

Re: how to convert 12december2015 to sas date value?

data _null_;
x='12december2015';
y=input(x,anydtdte32.);

put y= date9.;
run;
Contributor dpa
Contributor
Posts: 35

Re: how to convert 12december2015 to sas date value?

HI Ksharp

 

This one I did try but somehow gives missing value

 

Super User
Posts: 6,928

Re: how to convert 12december2015 to sas date value?


dpa wrote:

HI Ksharp

 

This one I did try but somehow gives missing value

 


Please show which input string results in a missing value.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 10,483

Re: how to convert 12december2015 to sas date value?

@KurtBremser

 

I get the same missing result using SAS 9.2 running your posted example.

Contributor dpa
Contributor
Posts: 35

Re: how to convert 12december2015 to sas date value?

data _null_;

252 x='12december2015';

253 y=input(x,anydtdte32.);

254

255 put y= date9.;

256 run;

y=.

 

log copy and pasted here

 

PROC Star
Posts: 1,558

Re: how to convert 12december2015 to sas date value?

27         data _null_;
28           x='12december2015';
29           y=input(x,anydtdte32.);
30           put y= date9.;
31         run;

y=12DEC2015  with SAS9.4 on WINx64
y=12DEC2015  with SAS9.4 on LINx64
y=.                    with SAS9.3 on Z/OS

 

This works in 9.3:

 

data _null_;
  X='12december2015';
  Y=input(prxchange('s/(\d{2}\w{3})\w*(\d{4})/$1$2/',1,X),date9.);
  put Y= date9.;
run;

☑ This topic is SOLVED.

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

Discussion stats
  • 12 replies
  • 438 views
  • 5 likes
  • 7 in conversation