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

I want to be able to use PNG files created by an external program.  I have a way to do it but the formatting does not conform to other outputs for this project.  Here is code that gets me close to what I want:

 

 

/* Create test data */
data test;
  drop i;
  call streaminit(1579);
  do i = 1 to 200;
    u = rand("Normal");
	output;
  end;
run;

/* Create a PNG file to bring into the RTF -- the PNG will
   actually be created outside of SAS but is included here
   for convenience */
proc sgplot data=test;
  density u / type=kernel;
run;

/* Set options for RTF output */
option nodate nonumber;
ods rtf file = "test.rtf" nogtitle nogfoot;
ods escapechar='~';

/* Titles and footnotes */
title 'Title';
/* Border line at the start of the footnote section */
footnote height=2pt '~R"\brdrb\brdrs\brdrw30';
footnote2 j=l 'Footnote';

/* Import the image and output into the RTF */
ods text='~S={preimage="SGPlot1.png"}';
ods rtf close;

 

 

Unfortunately, the image has no width, so it is hidden.  I would like to find a way to actually insert an image created from an external file and be able to see it without post-processing.  Additionally, I would like to be able to dictate the display size of the output so that creates the equivalent of the output from the following without having to create the image within SAS:

 

/* Set options for RTF output */
option nodate nonumber;
ods rtf file = "test1.rtf" nogtitle nogfoot;
ods escapechar='~';

/* Titles and footnotes */
title 'Title';
/* Border line at the start of the footnote section */
footnote height=2pt '~R"\brdrb\brdrs\brdrw30';
footnote2 j=l 'Footnote';

ods graphics / height=9in width=7in;

/* Import the image and output into the RTF */
proc sgplot data=test;
  density u / type=kernel;
run;
ods rtf close;

Notice that I've adjusted the size of the image so that it fills the page.  When I import an external PNG, I am not able to resize it, so the image quality is not as high as I would like it to be because I have to make sure that it is small enough so that it does not overrun the borders of the page.

 

Thank you for any help that you can provide.

1 ACCEPTED SOLUTION

Accepted Solutions
samdickson
Fluorite | Level 6

I did some digging and found that I could solve the problem with the width by adding 'width=100%' to the style as follows:

ods text='~S={width=100% preimage="SGPlot1.png"}';

In order to resize the image, I had to read it in as a text file and replace the rtf control words 'pichgoalN' and 'picwgoalN' with the dimensions I wanted.  The measurements are in twips, which is 1/1440 inch, so since I wanted 9in by 7in, I used 12960 and 10080, respectively:

data edit;
  infile "test.rtf" dlm='09'x dsd lrecl=32767 missover;
  format var $200. varout $200.;
  input var $;
  varout = prxchange("s/pichgoal\d+/pichgoal12960/",-1,var);
  varout = prxchange("s/picwgoal\d+/picwgoal10080/",-1,varout);
run;

data _null_ ;
  set edit ; 
  FILE  'test1.rtf' ;
  PUT varout; 
run ;

View solution in original post

1 REPLY 1
samdickson
Fluorite | Level 6

I did some digging and found that I could solve the problem with the width by adding 'width=100%' to the style as follows:

ods text='~S={width=100% preimage="SGPlot1.png"}';

In order to resize the image, I had to read it in as a text file and replace the rtf control words 'pichgoalN' and 'picwgoalN' with the dimensions I wanted.  The measurements are in twips, which is 1/1440 inch, so since I wanted 9in by 7in, I used 12960 and 10080, respectively:

data edit;
  infile "test.rtf" dlm='09'x dsd lrecl=32767 missover;
  format var $200. varout $200.;
  input var $;
  varout = prxchange("s/pichgoal\d+/pichgoal12960/",-1,var);
  varout = prxchange("s/picwgoal\d+/picwgoal10080/",-1,varout);
run;

data _null_ ;
  set edit ; 
  FILE  'test1.rtf' ;
  PUT varout; 
run ;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 1 reply
  • 7192 views
  • 2 likes
  • 1 in conversation