data:
accid
====
abc
abc
def
abc
xyz
def
desired output:
accid uniqid
==== =====
abc 1
abc 1
def 2
abc 1
xyz 3
def 2
Try this.
data have;
input accid $;
datalines;
abc
abc
def
abc
xyz
def
run;
proc sort data=have;
by accid;
run;
data want (rename=count=uniqid);
set have;
by accid;
if first.accid then count+1;
else count=count;
run;
Does
else count=count;
do anything?
Just by looking in your example, it looks like a surrogate key.
What's the application/requirement? This will just create 1-1 relationships.
If you want to work with lots of data and giving them surrogate keys (and more), look an ETL tool such as DI Studio.
If you don't want to sort you could do something like this. If you have multiple keys this will also work by creating a compound index and adding variables to the CLASS statement.
Thank you all, that helps!
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.
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.