Hi,
I have a dataset which I'd like to summarise in bands. 2 of my variables range in value from 0 to 100,000. I'd like to produce a report banding this data in groups of 5,000, i.e. summarise it in rows as follows:
0 - 5,000
5,000 - 10,000
10,000-15,000
...
95,000-100,000
Is there an easy way in which to do this, without having to do it programatically in a data step?
TIA
You can create a user defined format. You can even use a data step to create.
data cntl;
retain fmtname 'FiveK' type 'n';
do start = 0 to 95e3 by 5e3;
end = start + 5000;
label = catx('-',start,end);
output;
end;
run;
proc print;
run;
proc fmtlib cntlin=cntl;
run;
in the end I went with this:
Data xx;
Set yy;
Band = int(SumAssured/5000);
Run;
Then I sorted and summarised the dataset by Band. I was surprised it was so easy.
Thanks
This worked because your bands are equal sized. You still need a way to convert the band number to suitable display text though.
In general, you'll find PROC FORMAT to be your best friend in extremely flexible groupings like:
proc format;
value band
low - 0 = 'negative'
0 - 1000 = 'low'
1000 - 10000 = 'medium'
10000 - 100000 = 'high'
100000 - 1e6 = 'rich'
1e6 - 1e9 = 'filthy rich'
1e9 - high = 'obscene'
;
run;
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.