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
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;
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.
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
The 2025 SAS Hackathon Kicks Off on June 11!
Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.