Help using Base SAS procedures

How to categorize income zero as 0

Accepted Solution Solved
Reply
Super Contributor
Posts: 338
Accepted Solution

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

  1. 25.71

9

  1. 25.71

-8 to -9

1

  1. 2.86

10

  1. 28.57

1-41

5

  1. 14.29

15

  1. 42.86

42-392

15

  1. 42.86

30

  1. 85.71

<=-9

2

  1. 5.71

32

  1. 91.43

>392

1

  1. 2.86

33

  1. 94.29

Missing

2

  1. 5.71

35

  1. 100.00


Accepted Solutions
Solution
‎07-12-2012 03:26 PM
Grand Advisor
Posts: 10,062

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';

View solution in original post


All Replies
Solution
‎07-12-2012 03:26 PM
Grand Advisor
Posts: 10,062

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.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 154 views
  • 3 likes
  • 3 in conversation