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 |
| 9 |
|
-8 to -9 | 1 |
| 10 |
|
1-41 | 5 |
| 15 |
|
42-392 | 15 |
| 30 |
|
<=-9 | 2 |
| 32 |
|
>392 | 1 |
| 33 |
|
Missing | 2 |
| 35 |
|
|
|
|
|
|
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';
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';
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.
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!
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.
Ready to level-up your skills? Choose your own adventure.