PROC REPORT WITH MACRO - sas

I would like to create MACRO to produce a report (proc report) for each of datasets. For each report include title, "CYBOCS Compulsion Scale:Q6_#". Bold the line that has cycle 12 in it as cycle 12 is the primary endpoint. And using ODS RTF to output all reports to the personal drive
Here is the table look like:
Here is my code, I don't sure how to add bold line and how should I use ODS RTF to export reports
ODS RTF
%MACRO diff(var=);
PROC REPORT DATA=table_&var.;
TITLE "CYBOCS COMPULSION SCALE: &var";
RUN;
%MEND diff;
options mprint mlogic;
%diff(var=q6_1a);
%diff(var=q6_1b);
%diff(var=q6_2);
%diff(var=q6_3);
%diff(var=q6_4);
%diff(var=q6_5);
%diff(var=q6_6);
%diff(var=q6_7);
%diff(var=q6_date);

Use a compute block and add your condition. You can use call define() to conditionally change a style based on your logic. For example, if we wanted to bold the row for every BMW in sashelp.cars:
proc report data=sashelp.cars;
compute Make;
if(Make = 'BMW') then call define(_ROW_, 'style', 'style=[font_weight=bold]');
endcomp;
run;

Related

Output distribution charts in a pdf format? I only need the chart from a proc univariate of all the variables in a table

How can I output distribution charts in a pdf format? I only need the chart from a proc univariate of all the variables in a table - not any additional metrics.
ods pdf file="aaaa.pdf
TITLE 'Summary of Weight Variable (in pounds)';
PROC UNIVARIATE DATA = sashelp.class NOPRINT;
HISTOGRAM _all_ / NORMAL;
RUN;
ods pdf close
You use ODS SELECT _chartname_ to limit the output to what you want. You need to remove the NOPRINT option though or no output is generated to display regardless of destination.
It looks like univariate produces: CDFPlot, Histogram, PPplot, Probplot, QQplot so assuming you want just the histogram add the following line to your code:
ods select histogram;
Full code:
ods pdf file="aaaa.pdf;
ods select histogram;
TITLE 'Summary of Weight Variable (in pounds)';
PROC UNIVARIATE DATA = sashelp.class ;
HISTOGRAM _all_ / NORMAL;
RUN;
ods pdf close
Add it before or within your PROC UNIVARIATE.
PS. You're missing a semicolon on your ODS PDF statements at the top and bottom.
A good blog post from the SAS website on this is available here.

How to clear "Results" from Proc Univariate to show only a specific table

I´ve been using the UNIVARIATE proccedure in order to get the p-value from a series of distributions (lognormal, exponential, gamma) and have reached the following problem:
I am using the following code to get the p-values of the goodness of fit tests for each of the distributions:
ods select all/*ParameterEstimates GoodnessOfFit*/;
proc univariate data=results.Parametros_Prueba_1;
var Monto_1.;
histogram /
lognormal (l=1 color=red SHAPE=&ParamLOGN2_1 SCALE=&ParamLOGN1_1)
gamma (l=1 color=red SHAPE=&ParamGAM1_1 SCALE=&ParamGAM2_1)
exponential (l=2 SCALE=&ParamEXP1_1);
ods output GoodnessOfFit=results.Goodness_1;
run;
proc print data=results.Goodness_1;
After running the previous code I get the "Results" which gives me the histogram graphic and other descriptive information about the tests. I am looking for a way to get this "Results" print to show only the last part corresponding to the "proc print" added on the last line.
Thanks in advance!
If you want no output to the screen (results window) from PROC UNIVARIATE, then the simplest answer is:
ods select none;
proc univariate ... ;
run;
ods select all;
proc print ... ;
run;
ods select none; tells ODS to not make any ODS output whatsoever. You'll still get your ODS OUTPUT though as that comes in afterwards.
ods select none;
proc univariate data=sashelp.class;
var height;
histogram name='univhist' /
lognormal (l=1 color=red )
gamma (l=1 color=red )
exponential (l=2 );
ods output GoodnessOfFit=Goodness_1;
run;
ods select all;
proc print data=Goodness_1;
run;
Now, you'll note you don't get your histogram; that one is harder. It unfortunately changes its name every time you run it, and even if you use the NAME= option, that'll only work the first time it's run. You need to use PROC GREPLAY to delete it.
proc greplay nofs igout=work.gseg;
delete 'univhist';
run; quit;
(Assuming UNIVHIST is the name you assign it.)

ODS PDF - Two columns of output interrupted by one column of output on a single page

I'm trying to create an output for a requestor that wants me to take a preexisting report that comes in two columns on a single page and break it apart on that single page into different subsections, which they want indicated by a new title in the middle of the page where the new subsection begins.
What I have right now is:
ods pdf file=_pdf_ newfile=none startpage=no columns=2 notoc contents=no
style=swsp;
ods text = 'EMPLOYER RENEWAL DATA';
proc report data=renewal_data;
...
run;
ods startpage=now;
ods text='FINANCIAL DATA (FULL PROGRAM YEAR)';
proc report data=financial_data_total;
...
run;
ods startpage=now;
title1 '$ACA_YR_STR. ACADEMIC YEAR DATA';
footnote;
ods text='APPLICANT DATA';
...
run;
What I want is the page to have a section title where the second ods startpage=now is located that treats the entire page as one column, but then returns to two columns for the remainder of the page.
Thanks!
If you have SAS 9.4 (and possibly 9.3), you can use ODS LAYOUT to achieve this pretty easily. You need to create a gridded layout, and then change your title to another ODS TEXT (which you can of course style to be like a title). Titles go with PROCs, not by themselves, so if you actually use title it will appear where the next PROC REPORT goes, not in its own area.
Here's a barebones example that might get you started. See the ODS REGION and ODS LAYOUT documentation for more information. Note, this is something that is in production, but is also in active development, so different versions of SAS (including newer ones) may change how some of this works (though hopefully not break formerly existing functionality, who knows).
ods pdf file="c:\temp\test.pdf" startpage=no newfile=none notoc contents=no
style=swsp;
options obs=10;
ods layout gridded columns=2 rows=3;
ods region row=1 column=1;
ods text = 'CLASS DATA';
proc report data=sashelp.class;
columns name age;
run;
ods region row=1 column=2;
ods text='CAR DATA';
proc report data=sashelp.cars;
columns make model;
run;
ods region column_span=2 row=2 column=1;
ods text='ACROSS THE WHOLE PAGE NOW';
footnote;
ods region row=3 column=1;
ods text='NOT ACROSS WHOLE PAGE FOR THIS PART';
proc report data=sashelp.baseball;
columns name team;
run;
ods layout end;
ods pdf close;

SAS-Dynamically Writing Bar Charts to Excel workbook in SAS Macro

I am trying to dynamically generate and export bar charts to and an excel workbook. My Macro pulls certain distinct Identifier codes and creates two summary tables (prov_&x table and the prov_revcd_&x) and populates to single excel sheet, for each respective ID. I have been unable however to successfully generate bar charts for the data and export to excel. Below is a condensed version of code. I have removed the steps for creating the prov_&x table and the prov_revcd_&x table to help keep the post as concise as possible. I have tried using the GOUT function and NAME function and then explicitly calling those but that does not seem to work. Any suggestions are welcomed and I understand my macro code is a little sloppy but it generates the tables so I will clean up once I can get the bar charts to generate.
Also, I can see in my results viewer that the graphs are generating, so I'm assuming the problem is in how I am trying to reference them to the workbook. THANKS!
%macro runtab(x);
/*Create summary chart for generating graph of codes billed per month*/
proc sql;
CREATE TABLE summary_&x AS
select DISTINCT month, COUNT (CH_ICN) AS ICN_Count, CLI_Revenue_Cd_Category_Cd
FROM corf_data1_sorted
WHERE BP_Billing_Prov_Num_OSCAR=&x
group by month ,CLI_Revenue_Cd_Category_Cd;
run;
/*Create a graph of Services Per Month and group by the Revenue Code*/
proc sgplot data=summary_&x NAME= 'graph_&x';
title 'Provider Revenue Analysis';
vbar month / response=ICN_count group=CLI_Revenue_Cd_Category_Cd stat=sum
datalabel datalabelattrs=(weight=bold);
yaxis grid label='Month';
run;
%mend runtab;
/*Create a macro variable of all the codes */
proc sql noprint;
select BP_Billing_Prov_Num_OSCAR
into :varlist separated by ' ' /*Each code in the list is sep. by a single space*/
from provider;
quit;
%let cntlist = &sqlobs; /*Store a count of the number of oscar codes*/
%put &varlist; /*Print the codes to the log to be sure our list is accurate*/
/*write a macro to generate the output tables*/
%macro output(x);
ods tagsets.excelxp options(sheet_interval='none' sheet_name="&x");
proc print data=prov_&x;
run;
proc print data=prov_revcd_&x;
run;
proc print data=graph_&x;
run;
%mend;
/*Run a loop for each oscar code. Each code will enter the document generation loop*/
%macro loopit(mylist);
%let else=;
%let n = %sysfunc(countw(&mylist)); /*let n=number of codes in the list*/
data
%do I=0 %to &n;
%let val = %scan(&mylist,&I); /*Let val= the ith code in the list*/
%end;
%do j=0 %to &n;
%let val = %scan(&mylist,&j); /*Let val= the jth code in the list*/
/*Run the macro loop to generate the required tables*/
%runtab(&val);
%output(&val);
%end;
run;
%mend;
/*Run the macro loop over the list of significant procedure code values*/
ods tagsets.excelxp file="W:\user\test_wkbk.xml";
%loopit(&varlist)
ods tagsets.excelxp close;
You can't export charts with ODS TAGSETS.EXCELXP, unfortunately.
You have a few options if you need to export charts.
Use ODS Excel, available in the more recent maintenance releases of SAS 9.4. See Chris H's blog post for more information on that. It is fairly similar to Tagsets.ExcelXP, but not identical. It does generate a "Real" excel file (.xlsx).
Create an HTML file that Excel can read, using TAGSETS.MSOFFICE2K or regular HTML. Chevell Parker, a SAS tech support analyst, has a few papers like this one on the different options.
Use DDE to write your image to the excel file. Not a preferred option but included for completeness.
There is also a new proc - proc mschart - that is enabled in SAS 9.4 TS1M3 due out in a month or two, that will generate Excel charts in ODS EXCEL (ie, not an image, but telling Excel to make a chart here please).

SAS Ods RTF and PROC REPORT

So I've writen this:
ods rtf file = "D:\Sarath\List\2.rtf";
proc report data = list.lst1;
column PATIENT EOSDT STDRUG STDRUGSP STDCOMP STDCOMSP DAY5 EOSREAS;
define PATIENT/display "Subject * Number";
define EOSDT /order "Date of * Study Completion/ * Early Discontinuation";
define STDRUG/order "Administered*Study Drug?";
define STDRUGSP/display "If no,*Specify" ;
define STDCOMP/order "Completed*Dosing";
define STDCOMSP/display "If no,*Specify";
define DAY5/order "Completed*Study?";
define EOSREAS/display "Reason for * not Completing";
run;
ods rtf close;
and it creates an rtf with no data. Just a blank page. Please tell me what am I doing wrong here.
Regards.
Add nowd to the proc report line, otherwise SAS is expecting proc report to be an interactive procedure.
proc report data = list.lst1 nowd;
See documentation here:
http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a002473620.htm