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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 245 views
  • 0 likes
  • 3 in conversation