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

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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