SAS ODS RTF & proc report - sas

I'm trying to figure out why the formatting of my reports suddenly changed.
I had been exporting a report with 8 columns, all which fit on a single page in a word document. This month, it decided to put a page break in the middle (so the first 4 columns are on the first page, the second 4 columns are on the second page). Code didn't change at all.
So, thoughts:
data in the columns got bigger, so the width is no longer able to fit on one page. I thought the ods options "keepn" or "trkeep" would solve these problems, but neither made any difference.
some other sas setting made the column width defaults change. So I put "width=10" on the define statements within the proc report. Again, nothing changed.
My Code:
ODS RTF FILE="&REPORT_LOC./&outfile..rtf" keepn trkeep;
proc report data=FinalRpt2 nowindows headline headskip spacing=2 missing split='*';
column storeNum dept sales;
define storeNum / order width=10 'Store Number';
define dept / order width=10 'Department';
define sales / display width=10 'Sales';
run;

Related

I am trying to figure out how to sort this Dataset. SAS Beginner

How do i start this??
I have two data sets.
For the output you will deliver:
It should be an excel or XML format
Each query logic/programmed check should be on each tab
Columns should be
Subject #,
Visit Date (You will need the Visit Date Listing also attached)
Visit Name (Visit date from the file_34422 must match Visit name in the Blood Pressure File)
Date of Assessment (From the BP Log), VSBPDT_RAW, VSTPT, BP results.
A column for SYBP1. SYBP2, SYBP3, DIABP1, DIABP2, DIABP3
Findings/query text.
Below are Specification for BP:
For same SUBJECT and same FOLDERNAME, where VSTPT is Blood Pressure 1.
if VSBPYN is No, then all must be null or =0 (VSBPDT_RAW, VSBPTM1, SYSBP1, DIABP1, VSBPND2, VSBPTM2, SYSBP2, DIABP2, VSBPND3, VSBPTM3, SYSBP3, DIABP3)
This is what i have started with and
proc sql;
select
f.subject,
f.SVSTDT_RAW, f.FolderName,
b.FolderName,
VSBPDT_RAW, VSTPT,
SYSBP1, SYSBP2, SYSBP3,
DIABP1, DIABP2, DIABP3
FROM first_data as f, bp_data as b
group by subject, foldername
where f.subject = b.subject
having VSTPT is Blood Pressure set 1,
VSBPYN is No;
quit;
I just need to be pointed towards the right direction. I know this can't be right.
I do not know the exact structure of your data, so the solution below may need to be modified by you to select the right columns.
From the descritpion, this looks like it might be a good situation for SQL and a data step. You have a lot of columns to merge with the bp table. It will be easy to do merge all of these columns with first_data in SQL.
When you have lots of by-row conditionals, a data step will be easier to work with and read than many CASE statements in SQL. We'll do a two-stage approach in which we use SQL and a data step.
Step 1: Merge the data
proc sql noprint;
create table stage as
select t1.*
, t2.VSBPYN
from bp_data as t1
INNER JOIN
first_data as t2
ON t1.subject = t2.subject
AND foldername = t2.foldername
where t1.VSTPT = 1
;
quit;
Step 2: Conditionally set values to missing
Next, we'll do a data step for our conditional logic. call missing() is a useful function that will let you set the value of many variables to missing all in a single statement.
data want;
set stage;
if(upcase(VSBPYN) = 'NO') then call missing(VSBPDT_RAW, VSBPTM1, SYSBP1, DIABP1,
VSBPND2, VSBPTM2, SYSBP2, DIABP2,
VSBPND3, VSBPTM3, SYSBP3, DIABP3
);
run;
Step 3: Output to Excel
Finally, we sent the output to Excel.
proc export
data=want
file='/my/location/want.xlsx'
dbms=xlsx
replace;
run;

SAS ODS RTF - Best option to embed Title/Footnote into Table

Looking for advice to embed title/footnote as part of the table (see below - making it easier to copy & paste into the different document)
Options explored so far
1) PROC REPORT - COMPUTE PAGE BEFORE (COMPUTE doesn't support justification option and did not find any reliable option to right-align "page x of y" text in title1 e.g. calculating and inserting BLANK space. In addition, I have a need to center align the title)
2) ODS RTF - BODYTITLE and BODYTITLE_AUX option (displays title/footnote as part of the body but not exactly as part of the table - not easy to select as one object)
The SAS ODS inline styling directive ^{PAGEOF} will produce Page x of y output in the output file. Since the output is a Word field you might need to Ctrl-A, F9 to compute the field values when the document is opened.
The RTF destination renders TITLE and FOOTNOTE in the header and footer part of the documents, so tricks are needed to produce per-table 'titles' and 'footers'. From my perspective as a document reader, the best place for PAGEOF would be in the header section and not as part of a table header.
ods escapechar = '^';
title justify=right '^{PAGEOF}';
ODS TEXT= can be used to add paragraphs before and after a Proc TABULATE that does statistical reporting. ODS TEXT= will process inline ODS formatting directives (including PAGEOF). See SAS® 9.4 Output Delivery System: User’s Guide, Fifth Edition, ODS ESCAPECHAR Statement for more info.
ods text='
Narrative before tabular output via ODS TEXT=
^{NEWLINE} Inline styling directives will be processed.
^{NEWLINE} ^{STYLE [color=green]Mix and match}
^{NEWLINE} Let''s see why.
';
ods text='Here you are at ^{STYLE ^{PAGEOF}}';
* This might require Word field computation or print preview to get proper numbers;
Depending on the destination STYLE=, such as ods rtf style=plateau … ODS TEXT might have some outlining or other styling artifacts.
If you are rtf hardcore, ODS TEXT= can also inject rtf codes directly into the destination stream to produce any rtf possible production. In the following example:
legacy style function ^S{attr-name=attr-value} is used to force the text container to be 100% of the page width.
current style function ^{RAW function is used to introduce raw rtf coding. Each { of the actual rtf is introduced using {RAW. Note how the RAWs can be (and are) nested.
ods text = '^S={outputwidth=100% just=c} ^{RAW \rtf1\ansi\deff0^{RAW \fonttbl^{RAW \f0 Arial;}}
\qc\f0\fs20\i\b
This output created with ODS TEXT=\line
Injecting raw RTF coding\line
Such as ^{RAW \cf11\ul colored and underlined}\line
Not for the casual coder.
}';
Some procedures, such as Proc PRINT have style options such as style(table)=[ … ] in which a pretext= and posttext= can be specified, and such texts will be rendered before and after the rtf table -- the texts are not part of the table and would not be 'picked up' in a single click of Word's 'table select' icon (). Also, unfortunately, the pretext= and posttext= values are not processed for ODS styling directives. However, the values can be raw rtf!
PRETEXT demonstrating inline styling is not honored:
proc print
data=sashelp.class (obs=3)
noobs
style(table)=[
pretext='^{STYLE [color=Red]Above 1 ^{NEWLINE}Above 2 - Pretext= is unprocessed ODS directives}'
posttext='^{STYLE [color=Green] Below}'
]
;
run;
PRETEXT demonstrating as raw rtf passed through (when first character is {)
proc print
data=sashelp.class (obs=3)
noobs
style(table)=[
pretext='{\rtf1\ansi\deff0{\fonttbl{\f0 Arial;}}
\qc\f0\fs20\i\b This output created with SAS PRETEXT=
\line Injecting raw RTF coding
\line Not for the casual coder.
}'
posttext='{\rtf1\ansi\deff0{\fonttbl{\f0 Arial;}}
\qc\f0\fs20\i\b This output created with SAS POSTTEXT=
\line Injecting raw RTF coding
\line Not for the casual coder.
}'
]
;
run;
Proc TABULATE does not have a style(table) option, but the TABLE statement does have options:
/ CAPTION= (rendered when OPTION ACCESSIBLETABLE; active)
Note: Caption value is rendered in the page dimension container, so the caption value be overwritten if your TABLE statement has a page dimension in it's crossings.
/ STYLE=[PRETEXT='...' POSTTEXT='...']
Same caveats as mentioned earlier
TABULATE does not:
have any feature that will let you annotate a column header with a row statistic (in this case your (N=###) as part of the category value). A precomputation step that summarizes the crossings to be tabulated will allow you to place a statistic there.
provide any mechanism for inserting a blank or label row that spans the table (such as the LINE statement in Proc REPORT)
Consider this tabulate example with accessibletable on for some medical data. Some of the variables are for:
categorical demographics (such as sex),
continuous measures (such as age cost),
binary flags about state.
data have;
call streaminit(123);
do _n_ = 1 to 1e3 - 300 + rand('uniform',600);
patientId + 1;
category = ceil(rand('uniform',4));
age = 69 + floor(rand('uniform',20));
cost = 500 + floor(rand('uniform',250));
length sex $1;
sex = substr('MF', 1+rand('uniform',2));
array flags flag1-flag3; * some flags asserting some medical state is present;
do over flags; flags = rand('uniform', 4) < _i_; end;
output;
end;
label age = 'Age' cost = 'Cost' sex = 'Sex';
run;
* Precomputation step;
* Use SQL to compute the N= crossings and make that part of a
* new variable that will be in the tabulation column dimension;
proc sql;
create table for_tabulate as
select
*
, catx(' ', 'Category', category, '( n =', count(*), ')')
as category_counted_columnlabel
from have
group by category
;
quit;
Tabulation report
options accessibletable;
proc tabulate data=for_tabulate ;
class
category_counted_columnlabel
sex
/
missing style=[fontsize=18pt]
;
var age cost flag1-flag3;
table
/* row dimension */
age * ( mean std min max median n*f=8.) * [style=[cellwidth=0.75in]]
N='Sex' * sex
cost * ( mean std min max median n*f=8. )
(flag1 - flag3) * mean = '%' * f=percent5.1
,
/* column dimension */
category_counted_columnlabel = ''
/
/* options */
nocellmerge
caption = "This is caption text is ^{STYLE [color=green]from Mars}^{NEWLINE}Next line"
;
run;
For SAS versions before 9.4M6 you can add a page dimension variable (whose value is inlined ODS stylized text to be the caption) to the output of the precomputation step and specify that variable in the table statement. Something like
, '^{NEWLINE}title1' /* SQL step */
|| '^{NEWLINE}title2'
|| '^{NEWLINE}title3'
|| '^{NEWLINE}title4'
as pagedim_title
and
/* tabulate step */
class pagedim_title / style = [background=lightgray fontfamily=Arial textalign=right];
table pagedim_title, …, category_counted_columnlabel = '' … ;
It might be easier to edit the RTF.
read the file and count the occurrences of cf1{Page
{\field{*\fldinst { PAGE }}} of {\field{*\fldinst { NUMPAGES
}}}\cell}
then read again and write modify those lines as you write the new
file.

SAS: prevent proc report from applying comma format to display header title

I'm generating tables with rolling weeks of data, so my columns have to be named in the yyyymmdd format like 20161107. I need to apply a comma format to these columns to display counts, but the format is also being applied to the column name so 20161107 turns into 20,161,107. Below is example code that shows the error:
data fish; set sashelp.fish;
TEST = WIDTH*1000;
run;
ods tagsets.excelxp file = "C:\User\Desktop\test.xls" style=minimal
options(embedded_titles="yes" autofit_height="yes" autofilter="all");
proc report data = fish spanrows nowd &header_style.;
column SPECIES TEST;
define SPECIES / display;
define TEST / display "20161107"
f=comma12. style={tagattr='format:###,###,###'}; /* ERROR OCCURS WITH THIS STYLE */
title1 bold "sashelp.fish title";
run; title1;
ods tagsets.excelxp close;
It looks like I can fix this error by padding the display name with spaces like " 20161107 " but I'm not hardcoding these names, so I'd like to try to fix it in the proc report syntax first if possible. Any insight?
You should tell SAS to only apply that style to the column, then:
define TEST / display "20161107"
f=comma12. style(column)={tagattr='format:###,###,###'};
Then it should work as you expect.
Styles in PROC REPORT typically have multiple things they can apply to, and if you don't specify which they apply to all. style(header), style(report), etc. are all options - you can see the full list, plus a good explanation, in the SAS paper Using Style Elements in the REPORT and TABULATE procedures.

Break After & R Break

I am creating a report using proc report. My syntax runs fine but it doesnot shows the results of R break & After break in the output report. Thanks in advance
ods pdf file = "D:\New folder (2)\Assignment\Case_Study_1\Detail_Report.pdf";
proc report data = Cs1.Detailed_Report headline nowd ls = 256 ps = 765;
Title 'Olympic Pipeline (LONDON) - by Probability As of 17th November 2012';
column Probability Account_Name Opportunity_Owner Last_Modified_Date Total_Media_Value Digital_Total_Media_Value Deal_Comments;
where Probability > 0;
define Probability/group Descending 'Probability';
define Account_Name/order 'Client';
define Opportunity_Owner/order 'Champ';
define Last_Modified_Date/order format = MMDDYY. 'Modified';
define Total_Media_Value/order format = dollar25. 'Tot_Budget';
define Digital_Total_Media_Value/order format = dollar25. 'Digital_Bugt';
define Deal_Comments/order 'Deal_Comments';
break after Probability/ summarize suppress ol ul;
rbreak after / summarize ol ul;
run;
ods listing close;
ods pdf close;
Your main problem is that you don't have anything for the summarization to do. All of your columns are "ORDER" columns, which is probably not what you want. This is a common confusion in PROC REPORT; ORDER actually can be used in two different ways.
ORDER column type (vs. ANALYSIS, GROUP, ACROSS, COMPUTED, etc.)
ORDER= instruction for how to order data in a column (ORDER=DATA, ORDER=FORMATTED, etc.)
You can instruct SAS how to order a column without having to make it an ORDER column (which is basically similar to GROUP except it doesn't condense extra copies of a value if there are more than one).
If you want RBREAK or BREAK to do anything, you need to have an ANALYSIS variable(s); those are the variables that you want summaries (and other math) to work on.
Here is an example of this working correctly, with analysis variables. You need to tell SAS what to do, also, when summarizing them; mean, sum, etc., depending on what your desired result is.
ods pdf file = "c:\temp\test.pdf";
proc report data = sashelp.cars headline nowd ls = 256 ps = 765;
column cylinders make model invoice mpg_highway mpg_city;
where cylinders > 6;
define cylinders/group Descending;
define make/order;
define model/order;
define invoice/analysis sum;
define mpg_highway/analysis mean;
define mpg_city/analysis mean;
break after cylinders/ summarize suppress ol ul;
rbreak after / summarize ol ul;
run;
ods pdf close;

SAS rotate table 90 degree then output to pdf

Currently I use following code to output pdf.
GOPTIONS device=ACTXIMG;
ods pdf file="....\Daily Performance &CDate..pdf";
title 'Daily Performance';
proc tabulate data=DailyReport s=[just=c] missing;
class Area Period/order=data preloadfmt;
format Area $Areaformat. Period $Periodformat.;
var Units Uti Vari;
table (Area='' ),
(Units={Label="Units"}*(mean=''*f=comma6.)
Uti={Label="Uti"}*(sum=''*f=percent8.1)
Vari={Label="Var."}*(mean=''*f=percent8.1))/box="&CDate";
run;
ods pdf close;
But in some cases I have 20-30 columns in a tabulated output. If I use above code, then the table will be break into 2 or more pages in PDF.
So Is there a way to make it "vertical" in pdf? Or a way to keep it horizontal while compressed into one-page?
Change your page orientation using option orientation.
option orientation=landscape;
You change change the orientation within the document by changing the option between procs.