A Strange Affair: an Application Using SAS with Excel

A Strange Affair: an Application Using SAS with Excel

A Strange Affair: An Application Using SAS and Excel By Richard Chiofolo, Ph. D. Why Excel? Learning to Use Excel’s VBA Yes, it is strange. We learn that SAS is In most Finance departments today inclusive; “soup-to-nuts,” and can do outputs are in Excel format, or at least anything “under the sun.” It’s largely comma delimited (.csv) files easily read true. However, SAS does not have a by Excel. With the addition of VBA financial image. It is not a problem for code, a remake of an earlier markup those who use SAS, since we know its language, one can automate a lot of almost universal applicability. A quick activities in Excel. You can even design review of the financial “functions” in databases in sheets, entry screens, SAS proves the point to most intelligent links, and display screens. programmers. The overall capacity exists largely However, in Finance departments, because Excel is embedded in a much regardless of industry, SAS is not the larger engine design (Windows), which first tool of choice. Financial analysts now includes OOP “objects” usable will tell you “there is one and only one, across Microsoft applications. For older universal standard: Excel.” For those programmers of BASIC, VBA does not over fifty, Excel is the latest in a look like BASIC, but it is much richer progression from MultiPlan, VisiCalc, and application based than the original SuperCalc, Lotus 123, Symphony and language. However, it is not easy to use. other spreadsheet applications. Excel One must learn terms of the Windows was first released for Mac’s only. As operating system, and each object’s soon as it was available for the PC, it characteristics in each package (Excel, quickly became the dominant Word, Access, etc.). VBA is a lot more spreadsheet package for personal than the usual control structures like computers. In Finance, it is the standard “IF” and “DO”. More important, the tool, and has been for over ten years, objects are defined largely within the quite a feat among software products. context of the application package, in this case, Excel. It helps to know the Here is my goal: Excel package well before you learn to use the VBA objects. I must design an application in Excel, the product my users Normally I would have used SAS, on understand best. the mainframe, but in this case, my users recoil from mainframe based applications. I cannot even use Access, “Facilities” each have various Centers the appropriate Microsoft tool for and Accounts. database analysis and reporting. The users want to manipulate results further Finally, a field called MANCAT was (sorting, printing, copying) in a tool created which allows for a very high they already understand: Excel. I level rollup of the approximately two needed to automate the selection of hundred thousand records in our full records so that the user had an interface general ledger. These categories have to the data, not simply a dump of direct meaning to clients and they most records in a sheet. I knew that Excel had often want to see the location, centers pull-down menus, list and combo boxes and accounts associated with one of for selecting values and option buttons more of the MANCAT categories. for selecting criteria. I would have to learn how to use VBA code to automate The full key or “fully keyed account” for the process behind these Excel “Forms.” the database is thus: MANCAT, LOCATION, CENTER, and The General Ledger in a ACCOUNT. Hospital Corporation We use alphanumeric data for all fields. In SAS they are character fields, since Leaving SAS temporarily, I began we cannot treat them as computational analyzing Excel’s capacity to automate numbers. The rest of our record consists the selection and subtotaling of records. of various standard accounting The data used was a dump of the measures, Actual and Budget dollars general ledger in a large HMO spent in each fully keyed account, and corporation. Like most ledgers, it is FTE (full-time equivalent) headcounts. organized into Locations, Centers and To provide user requested comparisons, Accounts. Centers are equivalent to we include dollars for the current “departments,” organization or business month, prior month, and the same units for collecting costs and revenues. month last year, with both monthly and Here we are concerned only with “Cost year-to-date versions of the monthly Centers,” not “Revenue Centers.” Each figures. Center is divided into several Accounts that represent “cost functions” such as salaries, taxes paid, medical supplies, The Excel Application repair work, laundry charges, etc. We can also group Now, how do we allow users to review detail records, via automated selections, We are a very large corporation, and various rollups or subtotals of the subdivided into many locations. It is same data. For example, users want roll only relevant because the same center ups of all accounts in a Center or all can appear in more than one location. These physical “Locations” or locations in the same Service Area as a to it. I was experimenting with Excel’s total. implementation of Advanced Filter, a variation on the “Filter” function. It uses The easy part was implementing an “input range,” our database, an selections of records. Excel includes “output range” of the filtered records, several tools, such as “list” or “combo” and a “criteria range” that determines and “check” or “option” boxes for how to conduct the filtering of the selections. Each box is connected to a original data. It is analogous to our SAS “cell link” which allows me to see procedure PROC SUMMARY together numerically what selection the user with a WHERE to pick out which made, and a “macro code module” that summary is desired. The marriage automates a process for selecting occurred when I realized that records in a criteria range (see below). SUMMARY could generate all the possible combinations or summaries the The hard part was figuring out how to user wanted, and Excel’s FILTER summarize the detail records. Excel function would quickly select the provides two methods, an older chosen records that match a user’s “Subtotals” method, and a newer selection criteria. I would have to pre- system called “Pivot Table.” There are summarize the data in SAS first, which drawbacks. Subtotals inserts subtotals added more records, but I could avoid directly into the database of detail Excel processes delayed the display of records, wherever a break in the results. presorted data occurs. Once the subtotals are present in the data, you To implement Advanced Filter, we start cannot make further manipulations. The with a defined input range. As with Pivot Table method adds another sheet SUMMARY, this input does not need to to the application and needs user be pre-sorted. The output range (which intervention to implement and format. must lie in the same sheet as the input They can be automated, but I found that range, necessitating a final “COPY” the code was becoming too difficult to function to move the data to another manage. A path incorrectly chosen was “Display” sheet) can be limited. Excel leading me into convoluted fixes. only filters records for output columns that match input columns. There are over a hundred financial measures in Advanced Filter: The Chosen the input range, but only two columns Path (besides the keys) are needed. The user selects which dollar columns to output. After several weeks, a number of assist books on Excel’s VBA, and some The criteria range was more difficult to extensive experimentation, I found a figure out, since it must be intelligent simpler solution. What is strange is the and include several options, such as an unintended synthesis between the exact match, or the reciprocal: all strengths of SAS and Excel that led me records that do not match the specified value. The criteria range is complex subtotals are already present in the data. because there are so many options to This was the major breakthrough of this include. The user might want to see: application design. By using PROC SUMMARY to create subtotals 1) The detail records: a list of beforehand, Excel has only to extract fully keyed accounts. They them, no rollup occurs in Excel. may want to select only a few of them, by entering a single center for which they want to The SAS Summaries see all locations and all accounts. They may want the Using PROC SUMMARY without the other combinations, all NWAY option, we then use “bit” masks locations and centers for one to select which summaries and detail account, or all centers and records are needed by the application. accounts for one location or one Service Area (that is For example, here is the SAS code in a multiple locations in one data step for SUMMARY’s output file. Service Area). * CLASS MANCAT CENTER LOCATION 2) They may also want a custom ACCOUNT; IF _TYPE_ = '1111'B THEN DO; rollup of which there are RECTYPE='DETAILS'; OUTPUT; END; many combinations, but only ELSE IF _TYPE_ = '1000'B THEN DO; certain ones are likely, such RECTYPE='BYCSA '; OUTPUT; END; as: ELSE IF _TYPE_ = '1001'B THEN DO; RECTYPE='BYACCT'; OUTPUT; END; ELSE IF _TYPE_ = '1010'B THEN DO; a) By Center totals, all RECTYPE='BYLOCS '; OUTPUT; END; accounts and all ELSE IF _TYPE_ = '1011'B THEN DO; RECTYPE='ACCTLOC'; OUTPUT; END; locations. ELSE IF _TYPE_ = '1100'B THEN DO; b) By Account totals, all RECTYPE='BYCENT'; OUTPUT; END; centers and all ELSE IF _TYPE_ = '1110'B THEN DO; locations. RECTYPE='CENTLOC'; OUTPUT; END; ELSE IF _TYPE_ = '1101'B THEN DO; c) By Location totals, all RECTYPE='CENTACCT'; OUTPUT; END; centers and all accounts.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    8 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us