DATA Step, Macro, Functions and more

Create observation count variable - X

Accepted Solution Solved
Reply
Contributor
Posts: 35
Accepted Solution

Create observation count variable - X

[ Edited ]

Hi,

 

I have a cancer data set and I need to create an X variable (observation count). What's the codings used in this case.

 

Thanks


Accepted Solutions
Solution
‎05-11-2016 10:09 AM
Super User
Posts: 19,770

Re: Create observation count variable - X

SAS has an automatic variable that can be used as an observation counter. This assumes you want a row counter. If you want to count observations by groups or some other method you need to provide more details, preferably sample input and output. 

Data want;
Set sashelp.class;
X = _n_;

Run;

Proc print data=want label;
Run;

View solution in original post


All Replies
Solution
‎05-11-2016 10:09 AM
Super User
Posts: 19,770

Re: Create observation count variable - X

SAS has an automatic variable that can be used as an observation counter. This assumes you want a row counter. If you want to count observations by groups or some other method you need to provide more details, preferably sample input and output. 

Data want;
Set sashelp.class;
X = _n_;

Run;

Proc print data=want label;
Run;
Contributor
Posts: 35

Re: Create observation count variable - X

Thank you

Super User
Super User
Posts: 7,942

Re: Create observation count variable - X

Its always a good idea to post test data (in the form of a datastep), and what the output should look like.  We can only work with what you post here.  Do you mean you want an equivalent to the SAS automatic variable _n_ or a total observations?

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 314 views
  • 0 likes
  • 3 in conversation