BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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
3 REPLIES 3
Victor
Calcite | Level 5
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,
deleted_user
Not applicable
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.
Doc_Duke
Rhodochrosite | Level 12
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

hackathon24-white-horiz.png

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.

YouTube LinkedIn

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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