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
data want;
set have;
by empid;
if first.empid
then seqnum = 1;
else seqnum + 1;
run;
data want;
set have;
by empid;
if first.empid
then seqnum = 1;
else seqnum + 1;
run;
Can we do this same operation in proc sql step, without using data step?
@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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.