[英]SAS - extract 8-digit pattern with regex / prxmatch
從SAS中的現有字符串中提取格式為yyyymmdd
的日期戳的最佳方法是什么?
從我讀,最簡單的方法似乎是使用正則表達式withing的prxmatch
功能來代替一切,但格局。
[0-9]{8}
模式就足夠了。 這是我用empty
字符串替換8位數字模式(出於可讀性)的功能:
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;
我該如何更改,以便用字符串empty
替換除 9位數字模式以外的所有內容?
data b(keep=have want);
have='&libroot_hr./import/sxh3j900/20190702_SXH3J900_DWH_Adresse.txt';
re = prxparse("/(\d{8})/");
if prxmatch(re,have) then do;
want = prxposn(re,0,have);
end;
run;
如果您只想提取前8位數字。
這里的regexp為yyyymmdd格式。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.