/ Published in: SAS

Useful functions to ensure (99% of the time...) that a piece of text can be used to name a SAS variable. NOTE: This won't work with SAS literals.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
data _null_; name="1. Long text with no. at start - and some double spaces"; name = compress(strip(name), " ", 'kn'); ** Keep numbers, underscore character and letters (A - Z, a - z); name = translate(compbl(strip(name)),'_'," "); ** Convert dupe blanks to single and replace blanks with underscore; name = substrn(strip(name), 1, 31); ** Keep the first 31 chars (var name limit is 32); if input(substr(strip(name),1,1), ?? 3.) then name = "_"||name; ** Add "_" to names that start with a number; put name=; run;
Comments
