BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
gahlot1999
Fluorite | Level 6

I want to add SEQNUM variable in below dataset and I want numbering to get re-started from 1 as soon as EMPID changes....means for first 8 record SEQNUM should have normal....1, 2, 3...8 but for 9th record EMPID changed then it should have again 1, 2, etc. Like this for entire table.

Any easy way to do this.

I want to use proc sql only.

Current Dataset

gahlot1999_0-1651848289270.png

 

1 ACCEPTED SOLUTION
3 REPLIES 3
gahlot1999
Fluorite | Level 6

Can we do this same operation in proc sql step, without using data step?

Kurt_Bremser
Super User

@gahlot1999 wrote:

Can we do this same operation in proc sql step, without using data step?


Basically, no. SQL has no concept of sequence. There are methods to trick SQL into doing this, but they often rely on the use of undocumented (and therefore unreliable and dangerous) features. Apart from being (much) less performant than a data step.

Maxim 14: Use the Right Tool.

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

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 1530 views
  • 2 likes
  • 2 in conversation