BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
daszlosek
Quartz | Level 8

Hello everyone!

 

I need to convert a .RTF file into a .PDF file. I created the RTF with ODS RTF and proc report. I tried using ODS PDF, but the columns come out pretty weird so I thought using X command would be easier, the problem is, I can't figure out which executable  in Microsoft Office10 if the correct one for the x command. Is anyone familair with doing this? Here is the code I have so far:

 

 

x '"C:\Program Files\Office\Office14\_______.exe" c:\report\temp.rtf d:\report\tempxx.pdf /Y';

 

 

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

@daszlosek

Report writing is not what I'm normally doing so it can be that I miss the point. On a "high level" it's quite simple to add an additional output destination as demonstrated in below code. 

I assume if you have embedded output destination specific formatting in your Proc Report then it's another story.

%let RTF=C:\temp\test6.rtf;
%let PDF=C:\temp\test6.pdf;

ods _all_ close;
ods rtf file="&rtf";
ods pdf file="&pdf";
proc print data=sashelp.class;
run;
ods _all_ close;
ods listing;

 

View solution in original post

16 REPLIES 16
LinusH
Tourmaline | Level 20

Sounds like a "clean" Microsoft question.

You may be better off searching for the aswer at support.office.com or other MS focused sites.

Data never sleeps
daszlosek
Quartz | Level 8

Good idea! I have also posted it on the microsoft forums but I keep on getting asked why am I not manually opening the rtf and turning it into a pdf- which I could do, but the whole point it to automate the process.

SASKiwi
PROC Star

Is there a reason why you don't use ODS PDF directly with PROC REPORT?

daszlosek
Quartz | Level 8

I need both rtf and ods pdf files. I was given the ods rtf and proc report by the company and I just started working for an they have been manually making the pdf files. There are over 10 rtf files that are generated by this code and I thought using X commander would be easier than using ods pdf because I would have to customize each ods pdf code to fit the different rtf files.

SASKiwi
PROC Star

OK, but it still might be worth a quick test of direct PDF as you may find you only need to change your ODS statement. If not then revert to your original plan. 

Patrick
Opal | Level 21

@daszlosek

Report writing is not what I'm normally doing so it can be that I miss the point. On a "high level" it's quite simple to add an additional output destination as demonstrated in below code. 

I assume if you have embedded output destination specific formatting in your Proc Report then it's another story.

%let RTF=C:\temp\test6.rtf;
%let PDF=C:\temp\test6.pdf;

ods _all_ close;
ods rtf file="&rtf";
ods pdf file="&pdf";
proc print data=sashelp.class;
run;
ods _all_ close;
ods listing;

 

Patrick
Opal | Level 21

I totally agree with what @SASKiwi's question implies: Try a bit harder and make it work with ODS PDF instead of going for work-arounds too early.

 

But just for fun here a way of how to do it. It needs Word 2010 or higher installed on the machine where you execute the SAS code. 

%let RTF=C:\temp\test6.rtf;
%let PDF=C:\temp\test6.pdf;
%let vbscript=C:\temp\test6.vbs;

ods rtf file="&RTF";
proc print data=sashelp.class;
run;
ods rtf close;

filename vbscript "&vbscript";
data _null_;
  file vbscript;
  put
      "Const WORD_PDF = 17"
    / "Const WORD_IN=""&RTF"""
    / "Const PDF_OUT=""&PDF"""
    / "Set objWord = CreateObject(""Word.Application"")"
    / "objWord.Visible = False"
    / "Set objDocument = objWord.Documents.Open(WORD_IN,,False)"
    / "objDocument.SaveAs PDF_OUT, WORD_PDF"
    / "objDocument.Close False"
    / "objWord.Quit"
    ;
run;
filename vbscript;

options symbolgen;
data _null_;
  /* execute vbs */
  call system("&vbscript");
  /* clean up: delete rtf & vbs */
  call system("del /q &vbscript");
  call system("del /q &RTF");
run;
daszlosek
Quartz | Level 8

Hello Patrick,

I will try this on Monday morning and see if it works!  I have replied to SASKiwi's question as to why I dont just use ods PDF above.

 

 

Thank you all for your input and help- seriosuly I wonderful forum,

 

Donal S.

Emmayao
Calcite | Level 5

@Patrick

 

Hi Patrick,

I tried your code and found it works perfect when the path name does not contain space. Can you help me how to specify the path name with space? i.e. I:\Study Documents\test.rtf

 

Thanks,

Emma

Patrick
Opal | Level 21

Spaces and even worse '&' need just some additional quoting as done below:

 

%let RTF=C:\temp\test & test\test6.rtf;
%let PDF=C:\temp\test & test\test6.pdf;
%let vbscript=C:\temp\test & test\test6.vbs;

/** no changes below the line required */
%let rtf=%unquote(%str("&rtf"));
%let pdf=%unquote(%str("&pdf"));
%let vbscript=%unquote(%str("&vbscript"));

ods rtf file=""&RTF"";
proc print data=sashelp.class;
run;
ods rtf close;

filename vbscript ""&vbscript"";
data _null_;
  file vbscript;
  put
      "Const WORD_PDF = 17"
    / "Const WORD_IN="&RTF""
    / "Const PDF_OUT="&PDF""
    / "Set objWord = CreateObject(""Word.Application"")"
    / "objWord.Visible = False"
    / "Set objDocument = objWord.Documents.Open(WORD_IN,,False)"
    / "objDocument.SaveAs PDF_OUT, WORD_PDF"
    / "objDocument.Close False"
    / "objWord.Quit"
    ;
run;
filename vbscript;

options symbolgen;
data _null_;
  /* execute vbs */
  call system(""&vbscript"");
  /* clean up: delete rtf & vbs */
  call system("del /q "&vbscript"");
  call system("del /q "&RTF"");
run;
Emmayao
Calcite | Level 5

Thank you so much. It works great!

 

Best,

Emma

RajasekharReddy
Fluorite | Level 6

Hi Patrick,

 

Could you please help me how we can use this code to convert txt files to pdf 

 

at the same timce can we give pagenation in output pdf by using vbscript ?

 

Thanks in advance 

 

Patrick
Opal | Level 21

Hi @RajasekharReddy

 

Please don't post new questions into an existing thread but post a new question and copy/paste a reference link to the existing thread.

 

SAS has a ODS PDF destination so not sure if you need to use any non-SAS tools at all. Just post your question into forum "ODS and Base Reporting".

 

You will also need to provide a bit more detail of what you have and what you need; best already demonstrating some own work and thinking and if possible also providing sample data in form of a data step and then a description of the desired output.

 

Lenith
Obsidian | Level 7
You saved my Day. It works like nothing else. 🙂 Thank you very much!!

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 16 replies
  • 7792 views
  • 5 likes
  • 8 in conversation