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

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 280 views
  • 0 likes
  • 2 in conversation