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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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