Date: Thu, 16 Sep 2010 09:55:57 -0400
Reply-To: Chang Chung <chang_y_chung@HOTMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Chang Chung <chang_y_chung@HOTMAIL.COM>
Subject: Recoding based on frequencies
Saw this interesting question posted somewhere else. I tried, but could not
come up with a neat solution. Can you? Thanks.
"I have a series of categorical variables that I would like to recode based
on their frequency/count. [...] So, for example, if I had a series of
records in the variable being a, a, a, b, b, c, I would like to recode my
variable so that 'a ' (having the highest count) would be coded as 3 and
'c' (having the lowest count) would be coded as 1. Since I have a series of
variables it would be hard to recode them manually so was wondering whether
there was a command to easily do this."
Below is a test data I made up.
/* test data */
input id (v1-v5) ($);
1 a a a . a
2 a b b . a
3 a c c . a
4 b c d . a
5 b c e . a
6 c c . . a