BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Mirisage
Obsidian | Level 7

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

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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

2 REPLIES 2
ballardw
Super User

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

GeoffreyBrent
Calcite | Level 5

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.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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