BookmarkSubscribeRSS Feed
Obsidian | Level 7

ods rtf filename in '/home/u50158717/'; ( executing file with ods statement)

data NuclearPilotPlant;
input A B C D conv tc $ random;

filename out zip '/home/u50158717/';
ods rtf close;


How to do?


I am afraid I don't understand what you are trying to do.


Please provide additional details about:

  • your .sas program what sort of code it contain?
  • why do you write to a zip-file?
  • why the ods rtf close after the zip-file?


  When you use ODS RTF, you should be creating an RTF file in the FILE= option. Instead, your code shows a .SAS file extension, and shows the use of a FILENAME statement used as an option, both of which would be incorrect. I'm not entirely sure what you're trying to do, however, assuming that you are using a SAS OnDemand for Academics server account and your home folder location path is /home/u50158717, then something like THIS should make an ODS RTF file for you:

data newclass;
   set sashelp.class;
   if age ge 14 then output;

ods rtf file= '/home/u50158717/class_report.rtf';
proc print data=newclass;
  title 'Eligible for Driver Training Class Now and within 2 years';
  var name age sex;
ods rtf close;

The SASHELP library is loaded on the SAS OnDemand server, so you should be able to run this code. Note that the syntax for the ODS RTF statement uses a FILE= option and the result file and path are specified in the FILE= option. The DATA step that creates the file WORK.NEWCLASS is created OUTSIDE of the ODS RTF statements because 1) The DATA step is only creating a subset of rows from the SASHELP.CLASS file and so 2) does not produce any output that can be routed to the ODS RTF destination.

  In your code snippet, your code has many syntax errors. It looks more like pseudo code or some kind of mash-up of several different program examples.

  The purpose of the FILENAME statement is to point to an external file (such as a .CSV file or a .TXT file) for either INPUT or OUTPUT.

  You use the constructs FILENAME IN and FILENAME OUT in your code snippet. First of all, FILENAME is a separate statement and does NOT belong as part of an ODS RTF statement. The correct option for ODS RTF is FILE=, not FILENAME.

  Next, it looks like you're trying to read some data into a SAS format using code like this:

data NuclearPilotPlant;
input A B C D conv tc $ random;

  I'm not sure what the ... is for, but typically, I would expect to see more statements or a RUN; or a DATALINES or CARDS statement there. Not sure what your A=A; is needed for since, assuming your have a CARDS statement or a DATALINES statement followed by data, then your program should end with a RUN statement.

  If you are trying to READ data from an external file you could use either a FILENAME statement or an INFILE statement. Let's say you have a file called "nukes.txt" in your /home/u50158717 SAS OnDemand account then something like this would work:

data NuclearPilotPlant;
infile '/home/u50158717/nukes.txt';
input A B C D conv tc $ random;


filename nukein '/home/u50158717/nukes.txt';
data NuclearPilotPlant;
infile nukein;
input A B C D conv tc $ random;

  Without any reference to a DLM option, the assumption for this code would be that all of your variables were separated by blanks and that the only character variable in the data file was the TC variable.

  In either of the above programs, the unstructured data file, nukes.txt would be read into SAS using either the INFILE statement with the full path name or the FILENAME/INFILE statement and then the INPUT statement would parse the input lines and create 7 variables from each input line. Then each line or row would be output to the WORK.NuclearPilotPlant SAS data file.

  If you want to see the contents of this data file in an RTF file, then you would use PROC PRINT, as the simplest way to show you a report so you could review the data that you had just read into SAS format.

  We cover many of these basics of using SAS and PROC PRINT and ODS in our beginning Programming 1 class. This class is free to any independent learner.

  If you are using a data file and sample code provided by your professor, then you could ask your professor teaching assistant for working code examples that will work on the SAS OnDemand server.



Obsidian | Level 7

Thank you for the reply. I am inserting the print within What is supposed to be in the input file?  I just want an output file that I can edit?  Error message says file does not exist. Well it does not.

Mary Marion


%macro halfnorm(dsn,varname,n,cancel=);

/* Creates a half-normal plot
Data is N(0,sigma**2)

INPUTS are the effects from a Yates analysis or an ANOVA
dsn = Datafile, this is called by yatesGunstAnova and must stay dsn
varname = variable to be plotted
n = number of data points to be plotted
cancel = controls the creation of a fitted regression line through (0,0)
cancel=no draw
LVREF = line-type for vertical ref line, 2=dashed line

data halfnormal; set &dsn;

proc rank data=halfnormal out=ranks;
var abs_&varname;
ranks R;
run; quit; title;

data plotdata; set ranks;
RSTAR = (R-.5)/n;
p= RSTAR/2 + .5;
v = probit(p);

proc sort data=plotdata;
by descending abs_&varname; run;

ods rtf file= '/home/u50158717/plotdata.rtf';
title 'plotdata';
proc print data=plotdata; run; quit;
ods rtf close;

title 'v vs p'; run; quit;
plot v*p;
axis1 color=black label=(height=1.5 ) ;
axis2 color=black minor=none;
run; quit; title;

proc gplot data=plotdata;
PLOT v*abs_&varname /VREF=1 LVREF=2 REGEQN haxis=axis1 vaxis=axis2;
SYMBOL V=DOT I=RL0 COLOR=grey height=1.3 pointlabel=(height=10pt '#source' nodropcollisions) ;
run; quit; title;

options nocenter;
goptions reset=all;
ods graphics on;


Hi: Well, think of ODS statements as acting like the 2 pieces of bread in a sandwich. The top piece of bread starts the creation of an output file and names the file to be created (as appropriate for the destination -- which means ODS RTF creates an RTF file, ODS PDF creates a PDF file, ODS HTML creates an HTML file, ODS EXCEL creates an XLSX file, etc, etc). Then you have the filling in the sandwich -- the procedures that are going to send output to the ODS destination file -- This could be one procedure or it could be more than one procedure. Whatever the procedure creates will be sent to the ODS destination file, unless you apply some limits to ODS (like ODS SELECT or ODS EXCLUDE statements). Finally, the bottom piece of bread in the ODS "sandwich" is the ODS <destination> close. So if you open, ODS RTF, then you must close ODS RTF. If you open ODS HTML, you must close ODS HTML, etc, etc.
In your code, the ONLY output that will be sent to the ODS RTF file is the PROC PRINT output because of where your ODS RTF CLOSE; statement is located. Your 2 plots will probably show up in the default ODS HTML results window in SAS Studio. However, a bigger issue that I see is that you have a %macro statement at the very top of your code and there's no matching %mend statement. So given that this code is within a Macro Program definition, until you call or invoke the macro program, no files will be created. The only thing that happens when you submit code in a %MACRO/%MEND block of code is that the code is compiled and stored in a SAS Macro catalog. This catalog can be temporary or permanent. I don't see where you actually call the %halfnorm macro program or supply it with parameters. This is quite different code from the code you initially posted with the incorrect ODS RTF syntax. You say that you want an output file that you can edit. Assuming that you run the macro program and that the ODS RTF file is created, only your PROC PRINT results will be in the RTF file at the present time. That's assuming that everything works.
If you want the graphs and the PROC PRINT output to be in the RTF file, you'll need to move the ODS RTF close to the end, after the second GPLOT step.
If you ONLY want the PROC PRINT results, then in your folder, if the program runs successfully, you should see the ODS RTF output file with the name you provided in the FILE= option. You will need to download that file to your own machine, so you can open the file with Microsoft Word or some other word processing program.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 3 in conversation