need to convert id from character to numeric in the following fashion (to use in a panel data regression later):
idname idnumber
a 1
a 1
a 1
a 1
a 1
b 2
b 2
b 2
c 3
c 3
c 3
c 3
Then, sort your file by idname if it isn't already sorted and then run:
data want;
set have;
by idname;
if first.idname then idnumber+1;
run;
I'm not sure if your example was exactly representing what you want but, if it is, you could use:
data want;
set have;
idnumber=rank(idname)-96;
run;
hmm.. not exactly. i tried this, idnumber=rank(idnname)-50;
it starts with 1 but then misses some numbers. it shows as 1, 2, 4, 15.. and ends with 40 although i have 300 stocks (so the last idnumber should be 300).
there are just stock names, so should be by 'idname'. ( PROC PANEL will only run if for each stock a numeric is assigned)
idname year idnumber
stockA 96 1
stockA 97 1
stockA 98 1
stockB 96 2
stockB 97 2
stockC 96 3
stockC 97 3
stockC 98 3
stockC 99 3
Then, sort your file by idname if it isn't already sorted and then run:
data want;
set have;
by idname;
if first.idname then idnumber+1;
run;
yep. told it'd be simple. have tried a similar command before myself but somehow did not work.
I'm curious as to why you can't use StockA and need a number to identify each?
Usually you just add the idname in the class statement..
bcos i need to run PROG PANEL later, as i said, and it needs string or numeric.
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 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.