BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
bluetail
Calcite | Level 5

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

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

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;

View solution in original post

6 REPLIES 6
art297
Opal | Level 21

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;

bluetail
Calcite | Level 5

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

art297
Opal | Level 21

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;

bluetail
Calcite | Level 5

yepSmiley Happy. told it'd be simple.  have tried a similar command before myself but somehow did not work.

Reeza
Super User

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..

bluetail
Calcite | Level 5

bcos i need to run PROG PANEL later, as i said, and it needs string or numeric.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1413 views
  • 0 likes
  • 3 in conversation