In SAS, how can I assign serial numbers to observations in a data set?

To assign serial numbers to observations in a data set in SAS, create a variable using _N_, a system variable, which contains observation numbers from 1 through n. Consider the following example:

  DATA market_new;
  SET mydata_old;
      id = _N_;  
  RUN;

Here, id = _N_; copies observation numbers to the variable id.

If you have questions about using statistical and mathematical software at Indiana University, contact Research Analytics. Research Analytics is located on the IU Bloomington campus at Woodburn Hall 200; staff are available for consultation Monday-Friday 9am-noon and by appointment.

This is document adxp in the Knowledge Base.
Last modified on 2015-06-19 00:00:00.

Contact us

For help or to comment, email the UITS Support Center.