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