Desktop productivity for business analysts and programmers

New column, Counting observations?

Reply
N/A
Posts: 0

New column, Counting observations?

Is there a way to compute a column that counts observations and puts the current # in the new column.
DATA:
ID Date XYZ new column would show
1 06 123 1
1 07 124 2
2 06 113 1
3 06 234 1
3 06 235 2
3 07 345 3
Contributor
Posts: 36

Re: New column, Counting observations?

Hello

This is the solution. I suppose that data are in the the table named XXX and it is sorted by ID, DATE XYZ. The ZZZ table contains Z wich it counts the number of observations in each ID.

data ZZZ;
retain Z 0;
set XXX;
by ID;
if first.id then Z=0;
Z+1;
run;


Regards,
N/A
Posts: 0

Re: New column, Counting observations?

Thank you for the note. I'm afraid I was unable to make this work. In Enterprise Guide, where would I put this code? I tried it in the compute column box, but it doesn't get past "Retain" before it calls this a syntax error.
Trusted Advisor
Posts: 2,114

Re: New column, Counting observations?

Joe,

Victor's approach requires creating a Code Task to directly write the code; it's can't be used as an expression in the Query Task. I'm not sure how to do it in a query task, as SQL is inherently non-ordered in it's operations.

Doc Muhlbaier
Duke
Ask a Question
Discussion stats
  • 3 replies
  • 160 views
  • 0 likes
  • 3 in conversation