I am new to sas, basically I am trying to create bins that **go up by 0.05** for example
-2.5 to -2.45
-2.45 to -2.4
-2.40 to -2.35
-2.35 to -2.30
-2.30 to -2.25
so on
The bins range from -2.5 to 2.5. I want to create these bins and next to these bins I want to number of variables in this bin and then besides that column a cumulative percentage.
For example
.
Bin Number of Items Cumulative Frequency
-2.5 to 2.45 2% 2%
-2.45 to -2.4 3% . 5%
This is the example datset that I want to bin
Values
2.3
2.1
-2.5
-2.4
0.8
1.2
0.98
there are values like this in the data set
Ok I got it now. I think has a good solution . Alternatively adjusting the end of the code I had to the following could help as well:
data have2;
set have (in=a) forbin(in = b keep=binstart rename=(binstart=value));
if a then weight = 1;
if b then weight = 0;
run;
proc format library=work cntlin=forbin (rename=(binstart=start binend=end)); run;
proc freq data=have2;
format value bin.;
table value ;
weight weight / zeros;
run;
Good luck!
EJ
The following code might get you started. I wasnt sure in your description what the output you wanted should look like but I think it would be a matter of telling proc freq which columns you want to keep (table statement options).
data have;
infile cards dsd;
input value;
cards;
2.3
2.1
-2.5
-2.4
0.8
1.2
0.98
;
run;
data forbin;
drop i;
retain fmtname 'bin' type 'n';
do i = 0 to 300;
binstart = round(-4 + (i*.05),.01);
binend = round(binstart + .05, .01);
label = cat(binstart," to ", binend);
output;
end;
run;
proc format library=work cntlin=forbin (rename=(binstart=start binend=end)); run;
proc freq data=have;
format value bin.;
table value;
run;
Hope this helps!
EJ
Hey thank you so much my question is for example if we have bins -1.45 to -1.4 that dont have any values I want the cumulative percentage to continue. Proc freq only ouput bins that contain values and sums them up. I also want to display bins that dont have any values for example bins -1.5 to -1.45 cumulative percent might be 2% and the next bin -1.45 to -1.4 might not have any values I want the cumultiave percent of this bin to 2% also.
if you have the forbin dataset mentioned above...
proc sql;
create table want as
select
f.label,
sum(h.value is not null) as Records
from
forbin f
left join have h
on h.value >= f.binstart and h.value < f.binend
group by f.label
order by f.binstart;
quit;
hey does your code generate the cumulative frequency
Proc Freq will generate cum frequency by default when analyzing a single variable.
is there any way to display the bins that dont have any values because proc freq only displays the frequency of bins that do have values. For example if bins -1.45 to -1.4 dont have any values then proc freq skips them I want the cumultiave frequncy from the perovious bin to be in this bin.
Ok I got it now. I think has a good solution . Alternatively adjusting the end of the code I had to the following could help as well:
data have2;
set have (in=a) forbin(in = b keep=binstart rename=(binstart=value));
if a then weight = 1;
if b then weight = 0;
run;
proc format library=work cntlin=forbin (rename=(binstart=start binend=end)); run;
proc freq data=have2;
format value bin.;
table value ;
weight weight / zeros;
run;
Good luck!
EJ
Thank you so much will try it out
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.