« I Love Kung Fu Panda | Main | Free typing tests and games »

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.

Posted on Friday, January 23, 2009 by Registered CommenterJared in , | Comments2 Comments | References1 Reference

PrintView Printer Friendly Version

EmailEmail Article to Friend

References (1)

References allow you to track sources for this article, as well as articles that were written in response to this article.

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.

January 23, 2009 | Unregistered CommenterRichardK

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!

January 30, 2009 | Registered CommenterJared

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>