SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Whitlea
Obsidian | Level 7

Is there a way to add percent of the total for each clinic_name into this table?

proc sql ;
create table Gender as
select Clinic_Name,Gender, count(distinct ID)as Distinc_count, sum( Cost) as cost
from have
where Clinic_Type='1' and Cost>1 and SFY='2023'
group by Clinic_Name, Gender;
quit;

This is how I would like it to look:

snip.PNG

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
mkeintz
PROC Star

Looks like you want a report, not a data set.  Consider something like this:

 

proc format;
  picture mypct low-high=' 009.9% ';
run;
proc tabulate data=have noseps;
  class clinic gender ;
  var cost;
  table  clinic=' ' * gender=' '
       , N='Count'*f=5.0  sum=' '*cost='Cost'*f=dollar13.0
                          cost=' '*pctsum<gender>='%'*f=mypct.
       /Box="Clinic   Gender"  rts=20;
run;

I guess the percents that you want are percent cost for a given gender within a given clinic.  

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

It is not clear what percentage you are talking about.

Why would you use SQL to do that instead of a PROC like TABULATE which is designed to make sure reports?

mkeintz
PROC Star

Looks like you want a report, not a data set.  Consider something like this:

 

proc format;
  picture mypct low-high=' 009.9% ';
run;
proc tabulate data=have noseps;
  class clinic gender ;
  var cost;
  table  clinic=' ' * gender=' '
       , N='Count'*f=5.0  sum=' '*cost='Cost'*f=dollar13.0
                          cost=' '*pctsum<gender>='%'*f=mypct.
       /Box="Clinic   Gender"  rts=20;
run;

I guess the percents that you want are percent cost for a given gender within a given clinic.  

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

sas-innovate-white.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.

 

Early bird rate extended! Save $200 when you sign up by March 31.

Register now!

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
  • 2 replies
  • 550 views
  • 0 likes
  • 3 in conversation