## How to categorize income zero as 0

Solved
Super Contributor
Posts: 338

# How to categorize income zero as 0

Hi Community,

I have this data set. I havve categorised the "inocome" variable and got the freq distribution.

It gives the last output table shown at the bottom.

Q:

I need to get the freq band for zeros seperately. At present

"Income_Range" column of output table (see the bottom) categorises "zero" within

" -7 to 0" income band. But we like to impose a "0" income band separately.

Could anyone help me for coding. Thanks Mirisage

Data have;

input income;

cards;

0

15

.

392

219

95

208

-10

12

41

22

65

372

360

0

0

0

393

190

.

0

0

0

168

93

-8

0

14

43

138

52

125

0

-9

45

;

run;

data want;

length Income_Range \$20;

set have;

if Income = . then Income_Range='Missing';

else if Income   <=-9   then Income_Range = '<=-9';

else if Income   <=-8   then Income_Range = '-8 to -9';

else if Income   <=-1   then Income_Range = '-1 to -8';

else if Income   <=0  then Income_Range ='-7 to 0';

else if Income   <=41 then  Income_Range ='1-41';

else if Income   <=392 then  Income_Range ='42-392';

else Income_Range = '>392';

run;

proc freq data=want;

tables Income_Range;

run;

 Income_Range Frequency Percent Cumulative Cumulative Frequency Percent -7 to 0 9 25.71 9 25.71 -8 to -9 1 2.86 10 28.57 1-41 5 14.29 15 42.86 42-392 15 42.86 30 85.71 <=-9 2 5.71 32 91.43 >392 1 2.86 33 94.29 Missing 2 5.71 35 100.00

Accepted Solutions
Solution
‎07-12-2012 03:26 PM
Super User
Posts: 13,583

## Re: How to categorize income zero as 0

If I understand what you want change

else if income <= 0 <etc>.

to

else if income < 0 <etc> ;

else if income = 0 then Income_range = '0';

All Replies
Solution
‎07-12-2012 03:26 PM
Super User
Posts: 13,583

## Re: How to categorize income zero as 0

If I understand what you want change

else if income <= 0 <etc>.

to

else if income < 0 <etc> ;

else if income = 0 then Income_range = '0';

Contributor
Posts: 30

## Re: How to categorize income zero as 0

As an aside: if you're doing a lot of this categorisation, I recommend learning a bit of PROC FORMAT. It lets you define a coding scheme with fewer keystrokes, and makes it easier to reuse that scheme without cut-and-pasting large wodges of code.

🔒 This topic is solved and locked.