SAS Instructor Tip: Programming
Featured Instructor: Cynthia Johnson
How do I combine my SAS data sets and eliminate duplicate rows at the same time?
SAS Instructor Cynthia Johnson responds ...
SAS Instructor Tip: Programming
Featured Instructor: Kent Reeve
What happens when you forget the period on an informat when using formatted input?
SAS Programming Tips[1]
SAS/GRAPH Tip: Controlling the Graph Axis
SAS Instructor Cynthia Zender shows you how to control the graph axis through a feature of using the AXIS statement.
SAS ODS Tip: Creating Page X of Y Page Numbers
SAS Instructor Cynthia Zender shows you how to use the SAS ODS ESCAPECHAR to create a "Page X of Y Page Numbers"
SAS ODS Tip: Creating a Table of Contents
SAS Instructor Cynthia Zender shows you how to create a table of contents using the CONTENTS= Option with ODS RTF and ODS PDF destinations.
SAS ODS Tip: Controlling the Width of Cells
SAS Instructor Cynthia Zender shows you how to control the width and spacing of cells using STYLE=Overrides that have been designed for the ODS destinations that support STYLE.
SAS Programming Tip: Subsetting Data with a WHERE Statement
SAS Instructor David Ghan shows you how to to use a WHERE statement to subset your data.
Welcome to StudySAS, your ultimate guide to clinical data management using SAS. We cover essential topics like SDTM, CDISC standards, and Define.XML, alongside advanced PROC SQL and SAS Macros techniques. Whether you're enhancing your programming efficiency or ensuring compliance with industry standards, StudySAS offers practical tips and insights to elevate your clinical research expertise. Join us and stay ahead in the evolving world of clinical data.
Discover More Tips and Techniques on This Blog
Showing posts with label ODS escapechar. Show all posts
Showing posts with label ODS escapechar. Show all posts
Subscript or Superscript in the footers/titles of RTF output
Wondering how to create a subscripts and superscipt in title or footnotes of the rtf output... here is a way to do it....
Execute the following program to get an Idea about how to keep SUBSCRIPTS and SUPERSCRIPTS in footnotes and titles of rtf output..
************************************************************;
data test;
length secnam $15;
input sortord secnam $ pvalue;
cards;
1 demog 0.8812
2 ae 0.7112
3 disposition 0.8112
4 medicalhistory 0.9112
;
run;
ods listing close;
ods rtf file="Test output.rtf" style=rtfout;
ods escapechar='\';
proc report data = test missing split="$" spacing=0 headline nowd;
column sortord secnam pvalue;
define sortord / order noprint;
define secnam / order flow "Demographics$Variable\{super a}";
define pvalue / display flow "ANOVA$P-Value\{sub p}";
run;
ods rtf close;
ods trace off;
ods listing;
*************************************************************;
Variable\{super a}"; *Adds a superscript a to Demographics variable;
ANOVA$P-Value\{sub p}";*Adds a subscript p to ANOVA P-Value variable;
Make sure to use the same kind of brackets { }I have used in the sample code to get the superscripts and subscripts to get printed in the rtf output.
ESCAPECHAR need not be '\' as it is mentioned in the sample code... It could be '*' or '^' or '#' anything we can think of...
Execute the following program to get an Idea about how to keep SUBSCRIPTS and SUPERSCRIPTS in footnotes and titles of rtf output..
************************************************************;
data test;
length secnam $15;
input sortord secnam $ pvalue;
cards;
1 demog 0.8812
2 ae 0.7112
3 disposition 0.8112
4 medicalhistory 0.9112
;
run;
ods listing close;
ods rtf file="Test output.rtf" style=rtfout;
ods escapechar='\';
proc report data = test missing split="$" spacing=0 headline nowd;
column sortord secnam pvalue;
define sortord / order noprint;
define secnam / order flow "Demographics$Variable\{super a}";
define pvalue / display flow "ANOVA$P-Value\{sub p}";
run;
ods rtf close;
ods trace off;
ods listing;
*************************************************************;
Variable\{super a}"; *Adds a superscript a to Demographics variable;
ANOVA$P-Value\{sub p}";*Adds a subscript p to ANOVA P-Value variable;
Make sure to use the same kind of brackets { }I have used in the sample code to get the superscripts and subscripts to get printed in the rtf output.
ESCAPECHAR need not be '\' as it is mentioned in the sample code... It could be '*' or '^' or '#' anything we can think of...
Snapshot of output:
How to customize page numbers in RTF output
Usage Note 24439: In SAS 9.1, are there easier ways to customize page numbers in RTF output?
direct link here http://support.sas.com/kb/24/439.html
Yes, beginning with SAS 9.1, page numbers can be customized in the RTF destination by using an escape character and the {thispage} function, {lastpage} function, {pageof} function, or all three:
ods escapechar='^';
ods listing close;
ods rtf file='c:\tests\test.rtf';
data test;
do i=1 to 50;
output;
end;
run;
proc print data=test noobs;
title 'Page ^{thispage} of ^{lastpage}';
footnote '^{pageof}';
run;
ods listing;
ods rtf close;
direct link here http://support.sas.com/kb/24/439.html
Yes, beginning with SAS 9.1, page numbers can be customized in the RTF destination by using an escape character and the {thispage} function, {lastpage} function, {pageof} function, or all three:
ods escapechar='^';
ods listing close;
ods rtf file='c:\tests\test.rtf';
data test;
do i=1 to 50;
output;
end;
run;
proc print data=test noobs;
title 'Page ^{thispage} of ^{lastpage}';
footnote '^{pageof}';
run;
ods listing;
ods rtf close;
How to create a comma separated file (.csv) of a SAS dataset?
IN SAS programming, we often require outputting the dataset in different formats like EXCEL and CSV etc and here are the five different ways to export the SAS dataset into .csv file.
Example:
data new ;
infile datalines dsd dlm=' ' missover;
input a b c d;
datalines;
3 5 1 1
4 1 . .
5 8 3 2
6 0 4 4
;
run;
By putting MISSOVER in the infile statement we are telling SAS to do not look for the data in the next lane if it runs out of the data, instead keep missing values for any remaining variables.
DSD and DLM options should be included always in the infile statement, if we include the
dlm=’ ‘ in the infile statement then SAS will put one digit for each variable even though we haven’t assigned any length to variable.
DSD option will tell SAS to consider a missing value if 2 delimiters are present side by side in any observation.
When we ran the above program in SAS, we create a SAS dataset name ‘NEW’ in the work directory and if we want to create a .csv file of dataset ‘NEW’ here are the 5 different ways to do it:
1)Here is the simplest method and least known method to create the .CSV file of a dataset; Using the DEXPORT statement.
Here is the syntax:
dm "dexport new 'H:\abccompany\client\Programs\Analysis\project1\class.csv' ";
When we submit the above code, SAS will automatically create a .CSV file in specified location path.
2) .CSV file can also be created using the PROC EXPORT procedure:
Here is the syntax:
proc export data=new
outfile=" H:\abccompany\client\Programs\Analysis\project1\class.csv ";
run;
3) By using the ODS and the Proc print we will be able to create a .CSV file of SAS dataset.
Here is the way to do it;
ods csv file= ‘H:\abccompany\client\Programs\Analysis\project1\class.csv ';
Example:
data new ;
infile datalines dsd dlm=' ' missover;
input a b c d;
datalines;
3 5 1 1
4 1 . .
5 8 3 2
6 0 4 4
;
run;
By putting MISSOVER in the infile statement we are telling SAS to do not look for the data in the next lane if it runs out of the data, instead keep missing values for any remaining variables.
DSD and DLM options should be included always in the infile statement, if we include the
dlm=’ ‘ in the infile statement then SAS will put one digit for each variable even though we haven’t assigned any length to variable.
DSD option will tell SAS to consider a missing value if 2 delimiters are present side by side in any observation.
When we ran the above program in SAS, we create a SAS dataset name ‘NEW’ in the work directory and if we want to create a .csv file of dataset ‘NEW’ here are the 5 different ways to do it:
1)Here is the simplest method and least known method to create the .CSV file of a dataset; Using the DEXPORT statement.
Here is the syntax:
dm "dexport new 'H:\abccompany\client\Programs\Analysis\project1\class.csv' ";
When we submit the above code, SAS will automatically create a .CSV file in specified location path.
2) .CSV file can also be created using the PROC EXPORT procedure:
Here is the syntax:
proc export data=new
outfile=" H:\abccompany\client\Programs\Analysis\project1\class.csv ";
run;
3) By using the ODS and the Proc print we will be able to create a .CSV file of SAS dataset.
Here is the way to do it;
ods csv file= ‘H:\abccompany\client\Programs\Analysis\project1\class.csv ';
proc print data = new noobs;
run;
ods trace on;
ods csv close;
By keeping ODS trace on; statement we are telling SAS no to print the results in the output window, because, we are only creating the .csv file.
NOOBS option is required here, because PROC PRINT by default will create a new variable called 'OBS' and since we don't require it, we should include the NOOBS option.
4) File statement can also be useful in creating the .csv file of a SAS dataset.
Here is the way to do it.
data _null_;
file " H:\abccompany\client\Programs\Analysis\project1\class.csv ";
set new;
put (_all_) (',');
run;
5)b) Another way using the file statement:
filename csv ‘H:\abccompany\client\Programs\Analysis\project1\class.csv';
data _null_;
set new ;
file csv dlm=',';
put ( _all_ ) (+0);
run;
If we don’t mention the PUT( _all_), SAS will not keep all the variables in the .CSV file and even if we include put (_all_) the log will say:
ERROR 79-322: Expecting a (.
ERROR 76-322: Syntax error, statement will be ignored.
Because SAS is expecting a second parentheses here to follow the first one immediately and if we just only put the closed parenthesis to get rid of the previous error,
put (_all_) ( ) ;
We will get another error, because SAS we haven’t set any specifications for the PUT statement in the 2nd parenthesis.
So we can use a do-nothing pointer control (+0) to be error free.
Import CSV files and create SAS data sets on the fly!
Subscribe to:
Posts (Atom)
Disclosure:
In the spirit of transparency and innovation, I want to share that some of the content on this blog is generated with the assistance of ChatGPT, an AI language model developed by OpenAI. While I use this tool to help brainstorm ideas and draft content, every post is carefully reviewed, edited, and personalized by me to ensure it aligns with my voice, values, and the needs of my readers.
My goal is to provide you with accurate, valuable, and engaging content, and I believe that using AI as a creative aid helps achieve that. If you have any questions or feedback about this approach, feel free to reach out. Your trust and satisfaction are my top priorities.