BookmarkSubscribeRSS Feed
raveena
Obsidian | Level 7
Hi,

I need to generate an automated sequence number in the report.I have tried with monotonic options in proc sql and _n_ in data step...But am not getting an exact output.

SOURCE TABLE
ID________COMMENT
123_______I am joe
123_______I am programmer
124_______I am Wang
124_______I am programmer
124_______I like cricket

Output
ID_____SEQ______COMMENT
123_____1_______I am joe
123_____2_______I am programmer
124_____1_______I am wang
124_____2_______I am programmer
124_____3_______I like cricket

Can somebody please advise the way to do this in proc sql?

Thanks in Advance!
2 REPLIES 2
Doc_Duke
Rhodochrosite | Level 12
Raveena,

You probably need to do this in a DATA step. SQL doesn't generally recognize order with groups of an ORDER BY clause. RETAIN and FIRST are the concepts you need to read about to do this in a DATA step:

DATA out;
SET source;
BY id;
RETAIN seq;
IF first.id THEN seq=0;
seq+1;
RUN;

Doc Muhlbaier
Duke
raveena
Obsidian | Level 7
Thanks 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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 2 replies
  • 2696 views
  • 0 likes
  • 2 in conversation