is it right?n=_N_;

Reply
Occasional Contributor
Posts: 15

is it right?n=_N_;

here is my codes,but there are some mistakes. I do not know why the statement n=_N_ is wrong.

by using n=_N_, I want to get the serial number of the observations。

are there anyother to get the serial number of the observations?


proc sort data=raw;

by stkcd year month;

n=_N_;

run;

proc sort data=raw;  out=b;

by decending n;

run;

who can rewrite some code for me ? thank you very much.

PROC Star
Posts: 7,474

Re: is it right?n=_N_;

_n_ can only be used in a datastep.  Just remove that line from your proc sort call and preface the code with a simple datastep.  e.g.:

data raw;

set raw;

n=_n_;

run;

Super User
Super User
Posts: 7,050

Re: is it right?n=_N_;

Why not just use the DESCENDING keyword in your proc sort?

Or do you need the original order preserved in the variable N for some other purpose?

Ask a Question
Discussion stats
  • 2 replies
  • 593 views
  • 0 likes
  • 3 in conversation