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

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

1 ACCEPTED SOLUTION

Accepted Solutions
Loko
Barite | Level 11

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

12 REPLIES 12
Loko
Barite | Level 11

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;
dpa
Obsidian | Level 7 dpa
Obsidian | Level 7

Please can you explain 'ab' in scan function?

Loko
Barite | Level 11

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

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;
dpa
Obsidian | Level 7 dpa
Obsidian | Level 7

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

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;
Ksharp
Super User
data _null_;
x='12december2015';
y=input(x,anydtdte32.);

put y= date9.;
run;
dpa
Obsidian | Level 7 dpa
Obsidian | Level 7

HI Ksharp

 

This one I did try but somehow gives missing value

 

ballardw
Super User

@Kurt_Bremser

 

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

dpa
Obsidian | Level 7 dpa
Obsidian | Level 7

data _null_;

252 x='12december2015';

253 y=input(x,anydtdte32.);

254

255 put y= date9.;

256 run;

y=.

 

log copy and pasted here

 

ChrisNZ
Tourmaline | Level 20

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;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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