Automatically Generating a Customized Table for Summarizing the Activities in Clinics Yan Xu, Joyce X. Wu and Han Wu * Keywords: Automatically, Tabulate, INTCK, INTNX Abstract Automatically generating customized tables by using the SAS System is more reliable and efficient, particularly, when the tables need to be submitted periodically in report systems. An example SAS program using SAS/BASE and MACRO modules to create a comprehensive summary table is presented. The SAS program may be run on all SAS platforms. The SAS program features the INTCK and INTNX functions, PROC FREQ, and PROC TABULATE to create monthly reports that summarized weekly activities in the s. A SAS macro program is also described to add flexibility to the calculations shown in the PROC TABULATE table. Also, tips customizing the table and suppressing unnecessary displays were introduced. Introduction In the, many financial expense report tables need to be generated monthly, e.g., calculating costs for disease tests. The monthly report table needs to shows the number of medical tests and the price per test by disease conducted in each lab weekly. Also, the price per test may vary by the type of disease and by the number of the test conducted in a week (See table which was generated from a contrived data). Prior to using an SAS program to automatically generate the monthly report table, the table was typed in Excel. First, the frequencies of tests by diseases and labs in each week were obtained from running multiple PROC FREQ in SAS; secondly, based on the amount of tests in each week, the price per test for each disease was found from a price list; then, the subtotal and total costs were calculated; finally, the results were typed into a table in Excel. These procedures were not only time consuming but also hardly avoiding typos. In this paper, the steps of a SAS program automatically creating a comprehensive summary report table were discussed: (a) the data set from which the report is generated; (b) the calculation of frequencies for each test by each facility in each week using the functions INTCK and INTNX and PROC FREQ; (c) the creation of flexible price calculations using a SAS MACRO program; and (d) the creation and customization of the table in PROC TABULATE step. Data Set The data set DATA2003 (data source) contains the variables test_d (the date when test were conducted), disease (type test for different diseases), and lab (labs that conducted the tests). Creating Weekly Groups In the statement test_d=datepart(test_d); [1], the syntax DATEPART chopped the date part from the variable test_d which was in the datetime format. If the original data set was imported from Excel and Micro SQL, the syntax DATEPART is very useful to covert a date variable into a format that can be recognized by SAS. The statement of week=intck('week',intnx('month',test_d,0),test_d)+1; [2] generated a new variable week that indicated in which week of each month the test was conducted. First, the syntax INTNX('month',test_d,0) set the first day of the month of test_d, e.g., if the test_ d is 23apr2004, INTNX('month',test_d,0) will be the 01apr2004. Thus, SAS will read the original statement INTCK 'WEEK', INTNX('month',test_d,0), test_d)+1; as INTCK ('WEEK',01apr2004, 23apr2004)+1;. Then, the syntax
INTCK counted how many weeks from 01apr2004 to 23apr2004 based on the calendar. Finally, the variable week was generated and it indicated 23apr2004 is in the 4 th week. The statement mon=month(test_d); [3] generated a variable named mon that indicated the month in that the test was conducted. Thus, the steps [2] and [3] labeled each observation by new variables mon and week, that indicated in which month and in which week of the month the test was done. For example, if the test_d is 23apr2004, the mon will be 4 (April) and the week will be 4 (the 4 th week in the April). Price Tests In %macro price(&data1, &data2, c1_l, c1_h, p1, c2_l, c2_h, p2, c3_l, c3_h, p3, c4_l, c4_h, p4, c5_l, p5, dis); [4] generated the flexible prices per test based on the different disease and the test amount in each week. First, the frequencies of test amounts for different diseases in each lab and in each week were calculated by proc freq data=wuss12; [5] where mon=&mon; [6] tables lab3*week*disease/norow nocol nopercent out=temp1 noprint; Then, the results were outputted into data tepm1. Changing a unique month number in the statement where mon=&mon; and %let mon=1; [6] can generate the monthly reports in each month. In data &data1; [7], the macro variables c1_l to c5_l and c1_h to c4_h set the lower and higher limits of different test amounts; the p1 to p5 gave the prices for each range of test amount; the dis indicated the type of test. Thus, based on the test amount of each disease by each lab in each week, the price per test was created, when the %MACRO price was called in steps [8]. Creating Tables The PROC TABULTE DATA=temp2 summarized the total tests in each lab and in each week and calculated the subtotal and total costs of each test in each lab and in each week. Meanwhile, the option out=temp3 outputted the results to data tem3. The test numbers, price per test, and total cost were displayed in a table. However, the problem was the subtotals of the price per test were also displayed (The output was not shown). That did not make sense and might confuse end users. Thus, the output of the PROC TABULTE DATA=temp2 was suppressed by the statement ods listing close; [9]. In the DADT final set from DATA temp3, the step [10] recoded the subtotal of week as 7 that was formatted as Monthly total. In the step [11], subtotal of lab was recoded as Z that was formatted as All labs. In the step [12], the subtotal costs of price per test were recoded as 99 that was formatted as N/A. Thus, proc tabulate data=final2 created a table in that subtotal cost of price was displayed as N/A. The table made by one rum of an SAS program is easily readable and understandable for end users. The Program /*Figure 1. Create Weekly Groups with the Health Services Data Set*/ options nodate nonumber center; %let mon=1; [6] data wuss12; set data2003; if 01jan2003.d<=test_d<=31dec2003.d; if lab in (2, 3) then lab3="public Lab "; else lab3="private Lab"; test_d=datepart(test_d); [1] week=intck('week',intnx('month',test_d,0),test_d)+1; [2] mon=month(test_d); [3]
/*Figure 2. Macro for Pricing Tests*/ proc freq data=wuss12; [5] where mon=&mon; [6] tables lab3*week*disease/norow nocol nopercent out=temp1 noprint; %macro price(data1, data2, c1_l, c1_h, p1, c2_l, c2_h, p2, c3_l, c3_h, p3, c4_l, c4_h, p4, c5_l, p5, dis); [4] data &data1;; [7] set &data2; if count=0 then price=0; else if &c1_l <=count<=&c1_h and disease="&dis" then price=&p1; else if &c2_l <=count<=&c2_h and disease="&dis" then price=&p2; else if &c3_l <=count<=&c3_h and disease="&dis" then price=&p3; else if &c4_l <=count<=&c4_h and disease="&dis" then price=&p4; else if &c5_l <=count and disease="&dis" then price=&p5; subcost=price*count; %mend; %price(hiv_1,temp1, 1,10,5.50, 11, 20,4.50, 21, 30,3.50, 31, 40,2.50, 41,1.50, HIV); [8] %price(std_1,hiv_1, 1,50,6.50, 51,100,5.50, 101,200,4.50, 201,300,3.50, 301,2.50, STD); %price(temp2,std_1, 1, 5,7.50, 6, 10,6.50, 11, 15,5.50, 16, 20,4.50, 21,3.50, TB ); /*Figure 3. Creating Tables*/ ods listing close; [9] proc tabulate data=temp2 f=9.2 missing out=temp3; class lab3 week disease; var count price subcost; table lab3=""*(week=" " all= Lab Total") all="all labs", disease=' '* (count="count (n)"*sum=""*f=9.0 price="price/ test ($)"*sum=' ' subcost="subtotal ($)"*sum=' ') subcost="totoal Cost ($)"*sum="" / misstext="0" BOX="Lab and Week" RTS=20; format week weekfmt.; ods listing; data final; set temp3; if week=. and disease^=" " then week=7; if _type_=000 then week=7; [10] if lab3=" " and disease^=" " then lab3="z"; if _type_=000 then lab3="z"; [11] if week=7 or lab3="z" then price_sum=99; [12] proc format; value weekfmt 1="Week1" 2="Week2" 3="Week3" 4="Week4" 5="Week5" 6="Week6" 7="Monthly total"; [10] value $labfmt "Z"="All labs "; [11] value prifmt 99="N/A "; [12]
data final2; set final; if week^=. and disease^=" "; proc tabulate data=final2 f=9.2 missing ; class lab3 week disease; var count_sum price_sum subcost_sum; table lab3=" "*(week=" "*f=weekfmt.), disease=' '* (count_sum="count (n)"*sum=""*f=9.0 price_sum="price/ test ($)"*sum=""*f=prifmt. subcost_sum="subtotal($)"*sum=' '*f=9.2) subcost_sum="totoal Cost ($)"*sum=""*f=9.2 / misstext="0" BOX="Lab and Week" RTS=20; format lab3 $labfmt.; Title " The Monthly report of Weekly costs for tests of TB, HIV and STD in each Lab"; Title2 ", in &mon/2003"; Results Table The Monthly Report of Weekly Costs for Tests of TB, HIV and STD in Each Lab, January of 2003 ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ ƒƒƒƒƒƒƒƒƒ Lab and Week HIV STD TB ƒƒƒƒƒƒƒƒƒ ƒƒƒƒƒƒƒƒƒ ƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒ ƒƒƒƒƒƒƒƒƒ ƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒ ƒƒƒƒƒƒƒƒƒ ƒƒƒƒƒƒƒƒƒ Count Price/ Subtotal- Count Price/ Subtotal- Count Price/ Subtotal- Totoal (n) test ($) ($) (n) test ($) ($) (n) test ($) ($) Cost ($) ƒƒƒƒƒƒƒƒ ƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒ Private Week1 9 5.5 49.50 79 5.5 434.50 0 0 0 484.00 Lab ƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒ Week2 39 2.5 97.50 281 3.5 983.50 0 0 0 1081.00 Week3 22 3.5 77.00 224 3.5 784.00 0 0 0 861.00 Week4 34 2.5 85.00 204 3.5 714.00 1 7.5 7.50 806.50 Week5 20 4.5 90.00 273 3.5 955.50 6 6.5 39.00 1084.50 Monthly total 124 N/A 399.00 1061 N/A 3871.50 7 N/A 46.50 4317.00 ƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒ Public Week1 6 5.5 33.00 59 5.5 324.50 0 0 0 357.50 Lab ƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒ Week2 39 2.5 97.50 316 2.5 790.00 1 7.5 7.50 895.00 Week3 20 4.5 90.00 205 3.5 717.50 3 7.5 22.50 830.00 Week4 36 2.5 90.00 201 3.5 703.50 0 0 0 793.50 Week5 20 4.5 90.00 282 3.5 987.00 10 6.5 65.00 1142.00 Monthly total 121 N/A 400.50 1063 N/A 3522.50 14 N/A 95.00 4018.00 ƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒ All labs Monthly total 245 N/A 799.50 2124 N/A 7394.00 21 N/A 141.50 8335.00 Šƒƒƒƒƒƒƒƒ ƒƒƒƒƒƒƒƒƒ ƒƒƒƒƒƒƒƒƒ ƒƒƒƒƒƒƒƒƒ ƒƒƒƒƒƒƒƒƒ ƒƒƒƒƒƒƒƒƒ ƒƒƒƒƒƒƒƒƒ ƒƒƒƒƒƒƒƒƒ ƒƒƒƒƒƒƒƒƒ ƒƒƒƒƒƒƒƒƒ ƒƒƒƒƒƒƒƒƒ ƒƒƒƒƒƒƒƒƒœ
Conclusion Combining the functions of syntaxes INTCK, INTNX, PROC TABULATE, and MACRO skills directly created a monthly report table of costs of tests for different diseases. The tips to customize a table and suppress unnecessary displays in the table were introduced. By using PROC REPORT also can maneuver the displays of outputs to generate a similar report, but we think the table above from PRO TABULATE demonstrated the numbers more clearly. Automatically generating a summary table by a SAS program has advantages of more reliability and efficiency 1-4. The method and SAS programming skills are very useful to dispense data to clinics and to report data to the state and CDC for the County s and they should be used extensively in report systems. References : SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. indicates USA registration. 1. Han Wu, et al (2003). Automatically combining the data from a variety of DBMSs with ODBC and PROC SQL. Proceedings of 28 th Annual International Conference of SAS User Group International (SUGI). Seattle, WA, USA. 2. Han Wu, et al (2002). Using Automated Reports to Dynamically Monitor TB Control Performance. Proceedings of the National TB Controllers Workshops Association 2002. Alexandria, VJ, USA. 3. Han Wu (2002). Automatically Creating Pre-designed Report Tables to Monitor Tuberculosis Control Projects by a SAS Program. Proceedings of the 7 th Annual Conference of International Union against TB and Lung Disease 2002. Vancouver, BC, Canada. 4. Han Wu & Ying Chen (2001). Automatically Creating a Summary Table from Multiple Outcomes by a SAS Program. Proceedings of the Ninth Conference of Western User of SAS Software 2001, San Francesco, CA, USA. Contact information Yan Xu, MS Epidemiology Analyst STD Control Program Tel: (213) 744-0383 Email: yxu@dhs.co.la.ca.us Joyce X. Wu Student professional Worker STD Control Program Tel: (213) 744-5973 Email: jowu@dhs.co.la.ca.us HanWu, MD and MPH Epidemiologist Chief, Epidemiology Services Tuberculosis Control Program Tel: (213) 744-6243 Fax: (213) 749-0926 Email: hwu@dhs.co.la.ca.us *: All Authors are equal contributors.