```Date: Wed, 7 Sep 2005 12:14:16 -0400 Reply-To: Ya Huang Sender: "SAS(r) Discussion" From: Ya Huang Subject: Re: divide a data set into 2 subsets Comments: To: Haigang Zhou Here is a one step solution: data high low; set income (in=a_) income (in=b_); if a_ then do; total+inc; n+1; end; if b_ then do; if inc > total/n then output high; else output low; end; drop total n; run; HTH Ya Huang On Wed, 7 Sep 2005 11:47:45 -0400, Haigang Zhou 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; ```

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