BookmarkSubscribeRSS Feed
bcwhiteh
Calcite | Level 5
Greetings,

Currently I have a stored process that does a proc freq on a table of data. The 2 columns of interest are Facility and Contacts. I have a filter setup in the stored process to filter on the Facility. The table looks like this:

Facility, Contacts
A, 1
A, 2
B, 3
B, 10
C, 15


Now... in my stored process has the following code:
proc sort data=opmetric.sas_geo_2010all out=barron;
by descending facilityname descending contacts;
where state in (%stringGen(parm=state)) and facilityname in (%stringGen(parm=facility)); run;

proc freq data=barron order=data noprint;
tables state*city*facilityname / list out=contacts;
weight contacts;
run;
data finalcontacts (drop=percent);
set contacts;
cumcontacts+percent;
run;
data sasbase.geo2010all;
merge barron (in=c) finalcontacts (in=a) finalrounds (in=b);
if c;
run;


Now when I run this, this will calculate the frequency and cumulative % for each facility that I supply in the filter. So if I supplied Facilities A and B, the ending table would look like:
Facility, Contacts, % of Total, Cum %
A, 1, 6.25%, 6.25%
A, 2, 12.5%, 18.75%
B, 3, 18.75%, 37.50%
B, 10, 62.50%, 100%

However, what I would like for it to do is break out a cumulative % per Facility, instead of lumping every facility from the filter together. So Facility A would have its own cumulative %, then Facility B would have its own cumulative %. etc

Hope this makes sense

Thanks!
1 REPLY 1
TriciaA
Calcite | Level 5
Two solutions I can think of:

1 - Use a By statement to get the breakout for groups. However, I suspect you also want the overall value.

2 - I would use Proc Tabulate or Report for this particular application.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 1 reply
  • 1143 views
  • 0 likes
  • 2 in conversation