Reputation: 20906
I have the following SAS code that checks for patterns and flags any error.
I'm sure that it checks for a pattern in field1, but I'm not sure how two square brackets [] are evaluated.
I need to check for invalid values in field1.
sas code:
if prxmatch('/^[a-zA-Z][a-zA-Z0-9_]*$/', strip(&vfiel1)) = 0 then do;
put "Error is field1"
Upvotes: 0
Views: 337
Reputation: 1136
This regular expression will check for valid-looking SAS name. Specifically, it must start (^
) with a letter ([a-zA-Z]
) followed by 0 or more (*
) letters, numbers, and/or underscores ([a-zA-Z0-9_]
) before the end ($
).
A better SAS name check would be something along the lines of this:
^[a-zA-Z_][a-zA-Z0-9_]{0,7}$
^[a-zA-Z_][a-zA-Z0-9_]{0,31}$
Note these allow names to start with an underscore and have max lengths of 8 and 32 characters.
Here is a page on Names in the SAS Language.
Upvotes: 1