What's the best way of extracting a date-stamp with the format yyyymmdd
from an existing string in SAS?
From what I read, the easiest way seems to be using regular expressions withing the prxmatch
function to replace everything but the pattern.
- Let's assume that the only 8-digit pattern in the string will be my date, so a
[0-9]{8}
pattern is sufficient.
Here is what i have for replacing 8-digit patterns with the string empty
(for readability):
data b(keep=have want);
/* HAVE */
have = '&libroot_hr./import/sxh3j900/20190702_SXH3J900_DWH_Adresse.txt';
regexp = 's/[0-9]{8}/empty/';
times = -1; /* -1: replace all occurences */
/* WANT */
want = prxchange(regexp, times, have);
/* Result
'&libroot_hr./import/sxh3j900/empty_SXH3J900_DWH_Adresse.txt'
*/
run;
How can I change this, so it replaces everything but any 9-digit patterns with the string empty
?