@aasdfafafsdfsaf wrote:
ah i was understanding it wrong. have a follow up question. How would i modify this portion of the regex to include future possible changes to ID for example like looking for text such as USERID or UID, personID with 9 or 10 digit numbers? '/\bid[: ]+(\d([\d- ]){6,10}\d)\b/oi'
Something like below should work
'/\b(person|user|u)?id[: ]+(\d([\d- ]){9,12}\d)\b/oi'
With RegEx details matter and it's imho best to always test them with sample data that include all your desired patterns and ideally also the ones that are close but you don't want selected - like: a blank between person and id.
For ([\d- ]){9,12}: If you want to allow for multiple blanks then the upper boundary must be >10
If there shouldn't be any blanks between the digits then the RegEx would need to look like:
'/\b(person|user|u)?id[: ]+(\d{9,10}\d)\b/oi'
Something like this may do the trick:
data want;
set have;
length ID $8;
_N_=findw(str,'ID',': .');
if _N_ then
ID=compress(substr(str,_N_,14),,'DK');
run;
The parameters for the COMPRESS function simply deletes anything that is not digits, and because ID has a length of 8, only the first 8 digits are included. You may have to modify the parameters for the FINDW function to find all occurrences of "ID" (the parameters shown are the ones needed for the example data provided by @Patrick ). The third parameter (14) to SUBSTR is just a guess, we do not want to scan the whole rest of the string in case somebody entered an ID with only 7 digits in it (in which case the "14" should more or less guarantee that we do not get the first digit of the ZIP code or the date added to the ID).
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.