SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

Sum

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 14
Accepted Solution

Sum

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

Attachment

Accepted Solutions
Solution
‎03-03-2017 05:34 PM
Super User
Posts: 17,840

Re: Sum


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


All Replies
Super User
Posts: 10,501

Re: Sum

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.

Occasional Contributor
Posts: 14

Re: Sum

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

 

Super User
Posts: 17,840

Re: Sum

Is that what you have or want? 

 

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

Occasional Contributor
Posts: 14

Re: Sum

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.

Super User
Posts: 10,501

Re: Sum

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.

 

Occasional Contributor
Posts: 14

Re: Sum

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. 

Super User
Posts: 17,840

Re: Sum

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.  

Occasional Contributor
Posts: 14

Re: Sum

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. 

Solution
‎03-03-2017 05:34 PM
Super User
Posts: 17,840

Re: Sum


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. 

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

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