Macro %Report – Standard Scripts
This is a PhUSE collaboration project to provide a macro called %report which can be used to create outputs in a simple way. So this macro can be used instead of PROC REPORT. Please help us to enhance this macro by giving feedback, change requests, participate in the implementation, documentation, bug reporting, validation etc. With collaboration this macro can become very powerful and helpful for all of us.
This macro is based on the work of the PhUSE/FDA CSS group 5 “Development of Standard Scripts for Analysis and Programming” and uses the “Good Programming Practice” principles.
License and Disclaimer
The MIT license is used for this macro: http://opensource.org/licenses/MIT
Copyright (c) 2012 (PhUSE?)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
The following example displays the purpose of the macro:
TITLE "Example - simple CLASS example with BY"; %report(data = sashelp.class, var = age height weight, by = sex name);
Example - simple CLASS example with BY Sex Name Age Height Weight --------------------------------- F Alice 13 56.5 84 Barbara 13 65.3 98 Carol 14 62.8 102.5 Jane 12 59.8 84.5 Janet 15 62.5 112.5 Joyce 11 51.3 50.5 Judy 14 64.3 90 Louise 12 56.3 77 Mary 15 66.5 112 M Alfred 14 69 112.5 Henry 14 63.5 102.5 James 12 57.3 83 Jeffrey 13 62.5 84 John 12 59 99.5 Philip 16 72 150 Robert 12 64.8 128 Ronald 15 67 133 Thomas 11 57.5 85 William 15 66.5 112
By now the macro is a standalone macro and provides the following parameters:
|DATA||SAS input dataset, can contain WHERE, KEEP and similar conditions, e.g. SASHELP.CLASS(WHERE=(sex = ‘M’))|
|VAR||Variable(s) of DATA to be printed. Use _ALL_ to include all variables here that are not addressed in BY and PAGE optin of this macro|
|BY||Variable(s) to group and print|
|PAGE||Variable(s) to group and print. Printout above table start and starting a new page for all new values|
|MSGLVL||Option to define the levels of notes you want to get from this macro. 0: No additional messages, : Basic messages about the progress, Values above 1 not yet defined|
|FMT||Option to define formats for variables. Using this option will overwrite variables formats if these variables had some, Variables not included in this option are not affected. usage: FMT = <variable 1> = <variable 1 format incl. dot> .... <variable n> = <variable n format incl. dot>|
Following additional functionality is implemented:
|Existence Checks||DATA and VAR needs to be given|
DATA needs to be an existing valid dataset (WHERE, KEEP etc. supported)
|Column Width calculation||
The column widths of all BY and VAR variables are calculated based on the longest content & title of the corresponding column.
|Continued Flag||A continued flag is printed on all pages but the last.|
Requirements and Assumptions
- SAS 9.2 (maybe others as well)
- No formal validation is performed
- Simple quality checks are performed and can be found in a validation script (see documents section)
- Be aware that the code can be changed by anyone anytime
- If you need this macro validated it is up to you to check if all needed cases are contained in validation script and perform the validation on your own
- Macro Source: File:Report.sas.txt
- Example Validation Program: File:Report validation.sas.txt
- Example Call Program: File:Report example.sas.txt
- Example Call Output: File:Report examples.txt
Please report any change ideas you may have. Some could be discussed and some may be implemented. When you work on a change requests or have implemented and published those, please change the status. Use the status “Open” for new requests, “Ongoing” when you try to implement them and are going to publish a solution and “Finished” when done.
|Change001||Support printout of empty datasets containing variable labels and a “No Data Available” line (or similar) (KatjaGlass 2012-10-19)||Finished|
|Change002||Provide a nice DOC User Guide (KatjaGlass 2012-10-19)||open|
|Change003||Create nice lines, meaning one after the TITLEs and if available PAGE variable and one before the FOOTNOTEs (KatjaGlass 2012-10-19)||Comming soon|
|Change004||Include the PAGE label in the printout (KatjaGlass 2012-10-19)||Comming soon|
|Change005||Left align the output table (currently 2 leading spaces) (KatjaGlass 2012-10-19)||open|
|Change006||Support VAR=_ALL_, but exclude variables in PAGE and BY (KatjaGlass 2012-10-19)||Finished|
|Change007||Implement a better column widths calculation (KatjaGlass 2012-10-19)||open|
|Change008||Implement an ORDER variable, variables in PAGE and ORDER should not be printed and only be used for ordering purposes (KatjaGlass 2012-10-19)||Comming soon|
|Change009||Use a center alignment for column labels of VAR variables for BY use left alignment. (KatjaGlass 2012-10-19)||Comming soon|
|Change010||Option for level of messages (Raimund Storb 2012-11-12)||Finished|
|Change011||Bug fix for column format definitions for numerical paging variables. Use variables format if the variable has a format. Else use best. format.(Raimund Storb 2012-11-12)||Finished|
|Change012||Include macro option to assign a format to variable(s).(Raimund Storb 2012-11-12)||Finished|
|Change013||Include macro option to align variable(s) to left or right. Variables not covered here will be aligned in standard way. See also change 14(Raimund Storb 2012-11-14)||Comming soon|
|Change014||Implement a way to adopt the default alignment. At minimum the following shall be supported 1) All variables in BY option to the left, all other to the right. 2) all variables in the BY option and all character variables to the left, all other to the right. 3) All num. to the left, others to the right. (Raimund Storb 2012-11-14)||Comming soon|
|Change015||Parmeter LABEL to relabel the dataset (similar to reformat), use the direct <var1> "<label1>" ... <varX> "<labelX>" syntax, so the macro does not need to replace "=" which could be in the label as well (KatjaGlass 2012-11-18)||open|
|Change016||Parameter WIDTH as option to overwrite internal widths calculations, number of "widths" has to be identical to display variable numbers (KatjaGlass 2012-11-18)||open|
|Change017||Implement logical page breaking (keep groups together) (KatjaGlass 2012-11-18)||open|
Please report any found bugs. When you work on a bug-solution or have implemented and published those, please change the status. Use the status “Open” for new bugs, “Ongoing” when you try to fix them and are going to publish a solution and “Finished” when done.
|Bug001||Empty input datasets are not supported and abort with no catch message (KatjaGlass 2012-10-19)||Finished|
|Bug002||Numeric variables in by statement results in error messages because macro applies a character format. (Raimund Storb 2012-11-12)||Finished|
|Bug003||Continue flag appears on last page when the page-group has more than one observation. (Raimund Storb 2012-11-14)||Finished|
|0.1 (2012-11-01)||KatjaGlass||Initial creation containing DATA, PAGE, BY, VAR, column width calculation, continued footer|
|0.2 (2012-11-12)||Raimund Storb||Bug fixed, message level implemented|
|0.3 (2012-11-14)||Raimund Storb||Bug fixed,Calculate column width for numerical variables, Implement option to apply formats to variables|
|0.4 (2012-11-14)||Raimund Storb||Bug fixed, Empty datasets handling implemented|
Please participate in this project. Even if you only include change requests, bug fixes, then the community can take those items up. Even better if you participate also in creating implementations and documentations and join discussions. Please change available source, when you see enhancements in case of performance or simplify the source. Please do not use hardly to understand source and include comments.
Please enter items you want to discuss as many things can be handled very differently. The main goal for this macro is to keep things simple and reduce complexity by providing enough flexibility.