BookmarkSubscribeRSS Feed
mahender1
Fluorite | Level 6

Dear All,

How can i convert a string containing alphabets and date values and extract only date values from that.

Please find the below example:

The variable Details have the observations as below (dates not at particular position).

I need to extract the date values only.

 

Details

SAS_Anaytics_is_very_usefull_since_01Jan1960.

By_20Aug1990_it_has_become_more_powerfull.

Today_it_has_gained_huge_response_from_users_across_world_by_25Mar2020.

1 REPLY 1
PaigeMiller
Diamond | Level 26

I think you would have to break up the string into "words", and when one of the "words" is a valid date, you save it as a date (not a text string).

 

For example:

data want;
string='By_20Aug1990_it_has_become_more_powerfull.';
do i=1 to countw(string,'_');
    thisstring=scan(string,i,'_');
	date = input(thisstring,date9.);
	if not missing(date) then output;
	format date date9.;
	drop i thisstring;
end;
run;

 

--
Paige Miller

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 448 views
  • 0 likes
  • 2 in conversation