Date: Sun, 18 Mar 2001 17:01:29 GMT
Reply-To: Roger Lustig <julierog@IX.NETCOM.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Roger Lustig <julierog@IX.NETCOM.COM>
Subject: Re: Generate the third variable based on the categories of first
Content-Type: text/plain; charset=us-ascii
wei cheng wrote:
> Hi SAS-Lers,
> Sorry for the late Friday question.
No problem. We're open 24/7.
> If I have two categorical variables,
> Eg. variable A has levels x, y, z
> variable B has levels a,b,c,d
> and I need to create a third variable C based on them like:
> A B C
> y b a2b2
> x b a1b2
> x d a1b4
> z a a3b1
> y c a2b3
> .......
> We don't know the levels of A and B in advance, but we need to have variable
> C to have the levels of A and B.
Ya Huang already suggested a way of using FREQ and FORMAT to get the
order statistics and then concatenate the formatted values. There are
other implementations of the same approach, such as doing a FREQ on each
variable individually, an output data set for each, each of those data
sets becoming the CNTLIN data set to create a format. Then create your
new variable by concatenating formatted values of each input variable.
(This should be very easy to program into a macro, by the way.)
If you just need a unique value for C, one that does not reflect the
order statistics of A and B, you can simply concatenate the two
variables (if they're character) or use a transformation like
2**A * 3**B
if they're natural numbers.
Roger