Hi Forum,
I have taken the freq distribution of a variable named “income” employing this code (for confidentiality I cannot attach the data set).
data want;
length Income_Range $15;
set have;
if Income_ = . then Income_Range='Missing';
else if Income_ <=0 then Income_Range = '<=0';
else if Income_ <=80 then Income_Range ='>0 to <=80';
else if Income_ <=100 then Income_Range ='>80 to <=100';
else Income_Range = '>100';
run;
proc freq data=want;
tables Income_Range;
run;
Question:
However much I tried, the output table comes with “Income_Range” bands being jumped (meaning there are not in sequence).
Could anyone please let me know any reason for this?
Income_Range | Frequency | Percent | Cumulative | Cumulative |
Frequency | Percent | |||
<=0 | 82678 | 5.23 | 82678 | 5.23 |
>0 to <=80 | 1108529 | 70.12 | 1191207 | 75.35 |
>100 | 68658 | 4.34 | 1259865 | 79.69 |
>80 to <=100 | 321081 | 20.31 | 1580946 | 100 |
The sequence of Income_Range column of above table should have been like below.
Income_Range |
<=0 |
>0 to <=80 |
>80 to <=100 |
>100 |
Thank you for any help.
Mirisage
hi ... use a format (as suggested) or add some spaces ...
<=0
> 0 to <=80
> 80 to <=100
>100
That's because your variables are now characters and SAS is sorting it according to the character values, so 'alphabetic' order, which makes sense.
Using a format instead of recoding should solve that, if its an option.
hi ... use a format (as suggested) or add some spaces ...
<=0
> 0 to <=80
> 80 to <=100
>100
Hi MikeZdeb and Reeza,
Thank you very much for both of your responses.
Now I understand what has happened. Thanks Again.
Regards
Mirisage
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.