Return to Homepage

Goto the Tip of the Month Archive

Other interesting pages ...
LinkedIn Profile
SAS Cheat Sheet
Useful SAS Code
Full SAS Example
Basic Statistics
Contact Information

SAS Tip of the Month
May 2013
(for SAS and WPS)

Sometimes we want to add the observation number to a dataset. In the datastep we can easily do

   data dataset;
      set dataset;
      obsn=_n_;
   run;

However, if you are using SQL, this is not so easy. There is an undocumented function called the MONOTONIC function that will help, as the following code shows:

   proc sql;
      create table dataset as
         select monotonic() as N, *
         from dataset;
      quit;
    run;

Have a safe and happy May.

________________________________
Updated May 17, 2013