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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.