Return to Snippet

Revision: 51066
at September 13, 2011 19:10 by rambles

Initial Code
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=;


Initial URL

Initial Description
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.

Initial Title
Text to SAS Variable Name

Initial Tags

Initial Language