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

I'd like to pull date from a long character field.

For instance:

Out of another, I get a lovely view of the bay on 8/23/20 and a little private wharf belonging to the estate. There is a beautiful shaded lane that runs down there from the house. I always fancy I see people walking on 5/5/20.

 

From this I'd like my output to be:
date=08/23/2020

date=05/05/2020

Please help. Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

Use regular expressions matching. You can iterate the matches with prxNext:

 

data want;
if not prxId then prxId + prxParse("@\d\d?/\d\d?/\d\d(\d\d)?@");
set have;
start = 1;
stop = length(text);
call prxnext(prxID, start, stop, text, position, length);
do while (position > 0);
    date = input(substr(text, position, length), ?? mmddyy10.);
    if not missing(date) then output;
    call prxnext(prxID, start, stop, text, position, length);
    end;
keep date;
format date yymmdd10.;
run;
PG

View solution in original post

4 REPLIES 4
PGStats
Opal | Level 21

Can a sentence be "I'll see you on the first day of November 2020" ?

PG
Ja5ya
Fluorite | Level 6
No, this is the data we receive so we can't change the date format.
PGStats
Opal | Level 21

Use regular expressions matching. You can iterate the matches with prxNext:

 

data want;
if not prxId then prxId + prxParse("@\d\d?/\d\d?/\d\d(\d\d)?@");
set have;
start = 1;
stop = length(text);
call prxnext(prxID, start, stop, text, position, length);
do while (position > 0);
    date = input(substr(text, position, length), ?? mmddyy10.);
    if not missing(date) then output;
    call prxnext(prxID, start, stop, text, position, length);
    end;
keep date;
format date yymmdd10.;
run;
PG
Ja5ya
Fluorite | Level 6
Thanks for the regular expression! This worked out quite well.

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 758 views
  • 0 likes
  • 2 in conversation