BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Juli13
Fluorite | Level 6

How can I sum the CHC (in terms of patients and visits)?

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

@Juli13 wrote:

Yes there is going to be a lot of overlap.

I want to see the total of patients + visits in the year 2012, then 2013, then 2014 and so on. 


PROC MEANS. 

View solution in original post

9 REPLIES 9
ballardw
Super User

You need to provide some example data, just enough rows to show what you need. Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.

 

And then provide what you want for that example data. Since tabulate can provide sums in rows, columns, pages, within nested variables and overall for the data it really helps to know which subgroups you need the sums for.

 

Also since your example code has the line:

set services (where = (CHC = "AHL"));

then you can't "sum" chc at all as it is apparently a character variable and SAS does not sum character variables. It can COUNT them but not SUM them.

Juli13
Fluorite | Level 6

Sorry for the unclear question- I wish to group together all the CHC year wise and get the total no. of visits and patients for all the services year wise (ie. all the patients and visits for the 2012 for all the services in the year 2012 , 2013...and so on.) Basically I need two variables - year and (total visits + patients) Thank you! 

 

YearCHCServiceVisits Patients
2012AHLHIV test536521
2012AHLhepatitis B Test8582
2012AHLhepatitis C Test5047
2012AHLmammogram274261
2012AHLpap test15281416
2012AHLselected immunizations30372299
2012AHLseasonal flu vaccine20481968
2012AHLcontraceptive management26721387
2012AHLhealth supervision of infant or child (ages 0 through 11)38732652
2012AHLchildhood lead test screening (9 to 72 months)874839
2012AHLSBIRT00
2012AHLsmoke and tobacco use cessation counseling00
2012AHLcomprehensive and intermediate eye exam00
2012AHLemergency services00
2012AHLoral exams1268982
2012AHLprophylaxis - adult or child13761068
2012AHLsealants2727
2012AHLflouride treatment - adult or child955733
2012AHLrestorative services4848
2012AHLoral surgery11
2012AHLrehabilitative services33
2015AHLHIV test12651225
2015AHLhepatitis B Test6361
2015AHLhepatitis C Test271260
2015AHLmammogram15651502
2015AHLpap test20951991

 

Reeza
Super User

Is that what you have or want? 

 

Have you looked at proc freq, means or tabulate? They're probably where you want to start.

Juli13
Fluorite | Level 6

This is what I have-I am not able to group all the CHCs and Services together. How can I create a new table with the variables - year and patients+visits). I don't want the CHCs and Services variables.

ballardw
Super User

We still need more information such as what the original raw data looks like. It looks like what you have posted is a desired result which is good. Is your "patients" the number of unique patient identifiers you see in a year and visits the total count of all visits (including duplicates)? If so this may get you started.

 

proc sort data=work.services;
   by year patientid;
run;

data tab;
   set work.services;
   by year patientid;
   Indicator = first.patientid;
run;
proc tabulate data=tab;
   class year chc service;
   var indicator;
   table year*chc*service*indicator=""*(n='Visits' sum='Patients');
run;

Patientid would be whatever patient unique identifier you have. If you don't have one then you need explain in excructiating detail what the difference in your Visits and Patients results column are and how do we know which is which.

 

Juli13
Fluorite | Level 6

I don't have patient id. I want to see the total of patients + visits in the year 2012, then 2013, then 2014 and so on. 

Reeza
Super User

Actually this can't be your input table because if it is you can't Sum patients.

It's 100% likely some patients had multiple service, ie there's probably a big overlap in patients who have HIV and HEP B/C tests.

So you need to go a step back in your process and summarize the data before this step.  

Juli13
Fluorite | Level 6

Yes there is going to be a lot of overlap.

I want to see the total of patients + visits in the year 2012, then 2013, then 2014 and so on. 

Reeza
Super User

@Juli13 wrote:

Yes there is going to be a lot of overlap.

I want to see the total of patients + visits in the year 2012, then 2013, then 2014 and so on. 


PROC MEANS. 

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 connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 9 replies
  • 1550 views
  • 2 likes
  • 3 in conversation