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

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 542 views
  • 0 likes
  • 2 in conversation