SAS and Character Variable Lists
All this time I was doing things the hard way!
I new that a person could specify a range of variables, each with a numeric suffix, that SAS would enumerate over. But I didn't think that it worked with character variables.
With variables with a number sequence suffix, typing the following is cumbersome:
proc freq data=mydata;
tables var1 var2 var3 var4 var5;
run;
Instead do this:
proc freq data=mydata;
tables var1-var5;
run;
The same technique can be used on variables with a character (alphabetical) sequence suffix, but you use two dashes instead of one:
proc freq data=mydata;
tables varA--varE;
run;
You can read more about Variable Lists on Paul Dickman's site.
I came across a nice PDF that further explains "Dash" and "Double-Dash" variable lists.
References (1)
-
Response: SAS Variable Lists


Reader Comments (2)
A point of clarification here. The single dash tells sas to use a variable *list* while the double dash tells SAS to take a variable *range*.
So if my data set contained the variables id num1 num2 charA num3 charB, specifying the range charA--charB would include num3. Same idea applies numeric variables. variable lists (num1-num3) vs variable ranges (num1--num3); the range will include charA while the list wouldn't.
Wow! Thanks for pointing that out! That's an important piece of information.
Luckily, the range specified for my data does not include any unwanted variables. Not knowing the difference between List and Range could provide misleading results.
Thanks for the heads up!