Help using Base SAS procedures

add an column

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 118
Accepted Solution

add an column

hello,

I want to add a column of obs which count the number of observations by id

table

id     a    

1     2    

1     6    

1     5    

2     4    

2     9    

2     4    

2     5    

I want to have

id     a     obs

1     2     1

1     6     2

1     5     3

2     4     1

2     9     2

2     4     3

2     5     4


Accepted Solutions
Solution
‎11-18-2014 11:35 AM
Trusted Advisor
Posts: 1,204

Re: add an column

data want;

set have;

by id;

if first.id then obs=0;

obs+1;

run;

View solution in original post


All Replies
Solution
‎11-18-2014 11:35 AM
Trusted Advisor
Posts: 1,204

Re: add an column

data want;

set have;

by id;

if first.id then obs=0;

obs+1;

run;

☑ This topic is SOLVED.

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

Discussion stats
  • 1 reply
  • 152 views
  • 0 likes
  • 2 in conversation