Assign serial numbers to observations in a data set in SAS

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.

This is document adxp in the Knowledge Base.
Last modified on 2019-02-12 14:49:59.

Contact us

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