Date: Wed, 7 Sep 2005 09:13:18 -0700 monal kohli "SAS(r) Discussion" monal kohli Re: divide a data set into 2 subsets To: Haigang Zhou <200509071547.j87FaMQg006737@malibu.cc.uga.edu> text/plain; charset=iso-8859-1

Hi, This is one way to do this: data income; input id inc; cards; 1 43 2 89 3 45 4 13 5 90 6 67 ; run;

PROC MEANS DATA=INCOME; VAR INC; OUTPUT OUT=TEMP(KEEP=AVGINC) MEAN=AVGINC; RUN;

DATA HIGH LOW; IF _N_=1 THEN SET TEMP;

SET INCOME; IF INC>AVGINC THEN OUTPUT HIGH; ELSE OUTPUT LOW;

RUN;

HTH Monal

--- Haigang Zhou <hzhou3@UNLSERVE.UNL.EDU> wrote:

> I want to divide a data set into 2 subsets by the > average of a variable. > For example, I have an income data set, and I want > to divide it into two > sub sets. High if the income is above average, and > low otherwise. I can > achieve the goal using the following code, but I > have to manually input > the value for the mean. Is there is a way to do it > automatically? I > appreciate your kind help! > > * The raw data; > data income; > input id inc; > cards; > 1 43 > 2 89 > 3 45 > 4 13 > 5 90 > 6 67 > ; > run; > > * Calculate the mean value of income; > proc means data=income; > var inc; > run; > > * I have to manually enter the mean value of income > - 57.83; > data high low; > set income; > if inc > 57.83 then output high; > else output low; > run; >

______________________________________________________ Click here to donate to the Hurricane Katrina relief effort. http://store.yahoo.com/redcross-donate3/

Back to: Top of message | Previous page | Main SAS-L page