Reputation: 43
I want to create a column called rowno that is basically like a serial number to my existing table, so the deletion or selection of rows is easy even with duplicate values. INPUT:
Name Date Count
BAC 10/12 45
GBS 10/12 54
JDJA 10/13 89
SAK 10/13 11
YHN 10/14 76
JUK 10/14 76
OUPUT:
Name Date Count **ROWno**.
BAC 10/12 45 1
GBS 10/12 54 2
JDJA 10/13 89 3
SAK 10/13 11 4
YHN 10/14 76 5
JUK 10/14 09 6
Upvotes: 1
Views: 6062
Reputation: 486
You can use n operator in datastep.
Let’s say your input dataset is INPUT, use below data step to create a new dataset Output with column rownum
Data Output;
Set Input;
rownum = _n_;
run;
This code will work on any of the Sas box, sas eg, Sas studio etc.
Upvotes: 1
Reputation: 15657
monotonic() is an undocumented function which does what you want.
data have;
input Name $ Date $ Count;
datalines;
BAC 10/12 45
GBS 10/12 54
JDJA 10/13 89
SAK 10/13 11
YHN 10/14 76
JUK 10/14 76
;
proc sql noprint;
create table want as
select *,monotonic() as rowno from have;quit;
Upvotes: 0