College of Natural Sciences
 
FAQs
This is for IE7 to hold div open

SAS FAQ #9: Creating a counter variable in SAS

Question:

How do I create a count variable in SAS that reflects the order of the subjects in my raw data file?

Answer:

One way to do this is as follows. Include the following statement in your DATA step. It creates a variable ID which reflects the order of the observations in the raw data file.

id+ 1;

That is, the variable ID is assigned an integer value, starting at 1 for the first case, and increasing by one for each subsequent case in the data set.

If you have further questions, send E-mail to stats@ssc.utexas.edu.