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

Hello All,

 

I'm trying to create a panel of graphs created using 'proc plm'. I'm basing this on the PhUSE 2017 paper on 'combining ODS graphics output' by John Hendrickx. The outline of the code is below:

 

*********************************************************************************************;

ods _all_ close;
ods listing gpath="&png_dest" style=Pearl dpi=300;

ods graphics on /reset=index width=8.5cm outputfmt=png imagename='srsthirdt1';

 

proc plm ....
run;

 

ods graphics on /reset=index imagename='srsthirdt2';

 

proc plm ...
run;


ods graphics on /reset=index imagename='srsthirdt3';


proc plm ...
run;

ods graphics on /reset=index imagename='srsthirdt4';


proc plm ...
run;


data combine;
length c1 c2 $200;
c1= '^S={width=8.5cm just=center preimage="&png_dest\srsthirdt1.png"}';
c2= '^S={width=8.5cm just=center preimage="&png_dest\srsthirdt2.png"}';
output;
c1= '^S={width=8.5cm just=center preimage="&png_dest\srsthirdt3.png"}';
c2= '^S={width=8.5cm just=center preimage="&png_dest\srsthirdt4.png"}';
output;
run;


proc report data=combine nowindows style=[rules=none frame=void cellpadding=0] list;
columns c1 c2;
define c1-c2 /display ' ';
run;

*********************************************************************************************;

I can see that the graphs have been created in the location that I specified. When I run 'proc report', it gives me an error that "The width of c1 is not between 1 and 97. Adjust the column width or line size.".  On changing the column size to 97 (no specific reason to chose this number other than the error note), the output displays the location of the file:  ^S={width=8.5cm just=center preimage="&png_dest\srsthirdt1.png"}, for each of the 4 figures.

I've tried closing the ods listing as suggested in a few posts. I had an intuition that it wouldn't work in my case, but figured I'd try it anyway- Of course, it didn't. The other suggested option was to reduce the linesize, which led the location of the file to be displayed instead of the figures. I don't use proc report much and admit that I don't know all that the keywords are doing in the code!

 

Any suggestions are much appreciated.

 

Thanks!

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
unison
Lapis Lazuli | Level 10

Create dataset cowgmd for plm (from docs):

data cow;
	input current response trial experiment;
	datalines;
0  0 35 1
0  0 35 2
1  6 35 1
1  3 35 2
2 13 35 1
2  8 35 2
3 26 35 1
3 21 35 2
4 33 35 1
4 27 35 2
5 34 35 1
5 29 35 2
;

data prior;
	input _type_$ current;
	datalines;
mean 100
var   50
;

proc genmod data=cow;
	class experiment;
	bayes coeffprior=normal(input=prior) seed=1;
	model response/trial=current|experiment / dist=binomial;
	store cowgmd;
	title 'Bayesian Logistic Model on Cow';
run;

Applying the method in the PhUSE paper you mentioned:

 

%let png_dest = /folders/myfolders/sasuser.v94;
ods _all_ close;

ods listing gpath="&png_dest" style=Pearl dpi=300;
ods graphics on /reset=index width=8.5cm outputfmt=png imagename='png1';

proc plm source=cowgmd;
	estimate 'Diff at current 0' experiment 1 -1 current*experiment [1, 0 1] [-1, 
		0 2] / plots=boxplot(orient=horizontal);
run;

ods graphics on /reset=index width=8.5cm outputfmt=png imagename='png2';

proc plm source=cowgmd;
	estimate 'Diff at current 1' experiment 1 -1 current*experiment [1, 1 1] [-1, 
		1 2] / plots=boxplot(orient=horizontal);
run;

ods graphics on /reset=index width=8.5cm outputfmt=png imagename='png3';

proc plm source=cowgmd;
	estimate 'Diff at current 2' experiment 1 -1 current*experiment [1, 2 1] [-1, 
		2 2] / plots=boxplot(orient=horizontal);
run;

ods graphics on /reset=index width=8.5cm outputfmt=png imagename='png4';

proc plm source=cowgmd;
	estimate 'Diff at current 3' experiment 1 -1 current*experiment [1, 3 1] [-1, 
		3 2] / plots=boxplot(orient=horizontal);
run;

Key changes I had to make to get the next part to work:

1. Rewrite the combine step so that the macro variable for the folder path resolves.

2. Add 'ods escapechar '^' so that the style carat is escaped.

 

data combine;
	length c1 c2 $100;
	c1=cats('^S={width=8.5cm just=center preimage="', "&png_dest", '/png1.png"}');
	c2=cats('^S={width=8.5cm just=center preimage="', "&png_dest", '/png3.png"}');
	output;
	c1=cats('^S={width=8.5cm just=center preimage="', "&png_dest", '/png3.png"}');
	c2=cats('^S={width=8.5cm just=center preimage="', "&png_dest", '/png4.png"}');
	output;
run;

ods html file="&png_dest/test.html" style=sasweb; ods escapechar='^'; proc report data=combine nowindows style=[rules=none frame=void cellpadding=0] list; columns c1 c2; define c1-c2 /display ' '; run;

download.png

 

 

-unison

-unison

View solution in original post

14 REPLIES 14
unison
Lapis Lazuli | Level 10

Create dataset cowgmd for plm (from docs):

data cow;
	input current response trial experiment;
	datalines;
0  0 35 1
0  0 35 2
1  6 35 1
1  3 35 2
2 13 35 1
2  8 35 2
3 26 35 1
3 21 35 2
4 33 35 1
4 27 35 2
5 34 35 1
5 29 35 2
;

data prior;
	input _type_$ current;
	datalines;
mean 100
var   50
;

proc genmod data=cow;
	class experiment;
	bayes coeffprior=normal(input=prior) seed=1;
	model response/trial=current|experiment / dist=binomial;
	store cowgmd;
	title 'Bayesian Logistic Model on Cow';
run;

Applying the method in the PhUSE paper you mentioned:

 

%let png_dest = /folders/myfolders/sasuser.v94;
ods _all_ close;

ods listing gpath="&png_dest" style=Pearl dpi=300;
ods graphics on /reset=index width=8.5cm outputfmt=png imagename='png1';

proc plm source=cowgmd;
	estimate 'Diff at current 0' experiment 1 -1 current*experiment [1, 0 1] [-1, 
		0 2] / plots=boxplot(orient=horizontal);
run;

ods graphics on /reset=index width=8.5cm outputfmt=png imagename='png2';

proc plm source=cowgmd;
	estimate 'Diff at current 1' experiment 1 -1 current*experiment [1, 1 1] [-1, 
		1 2] / plots=boxplot(orient=horizontal);
run;

ods graphics on /reset=index width=8.5cm outputfmt=png imagename='png3';

proc plm source=cowgmd;
	estimate 'Diff at current 2' experiment 1 -1 current*experiment [1, 2 1] [-1, 
		2 2] / plots=boxplot(orient=horizontal);
run;

ods graphics on /reset=index width=8.5cm outputfmt=png imagename='png4';

proc plm source=cowgmd;
	estimate 'Diff at current 3' experiment 1 -1 current*experiment [1, 3 1] [-1, 
		3 2] / plots=boxplot(orient=horizontal);
run;

Key changes I had to make to get the next part to work:

1. Rewrite the combine step so that the macro variable for the folder path resolves.

2. Add 'ods escapechar '^' so that the style carat is escaped.

 

data combine;
	length c1 c2 $100;
	c1=cats('^S={width=8.5cm just=center preimage="', "&png_dest", '/png1.png"}');
	c2=cats('^S={width=8.5cm just=center preimage="', "&png_dest", '/png3.png"}');
	output;
	c1=cats('^S={width=8.5cm just=center preimage="', "&png_dest", '/png3.png"}');
	c2=cats('^S={width=8.5cm just=center preimage="', "&png_dest", '/png4.png"}');
	output;
run;

ods html file="&png_dest/test.html" style=sasweb; ods escapechar='^'; proc report data=combine nowindows style=[rules=none frame=void cellpadding=0] list; columns c1 c2; define c1-c2 /display ' '; run;

download.png

 

 

-unison

-unison
sas_epi
Calcite | Level 5

Hello Unison,

 

Thank you for your comments and code. It didn't work out quite as expected though. The code that I used is below. As you can see, when I used a column length of 150, I get the error that the length needs to be between 1 and 97

 

data combine;
	length c1 c2 $150;
	c1= cats('^S={width=8.5cm just=center preimage="', "&png_dest", '\srsthirdt1.png"}');
	c2= cats('^S={width=8.5cm just=center preimage="', "&png_dest", '\srsthirdt2.png"}');
	output;
	c1= cats('^S={width=8.5cm just=center preimage="', "&png_dest", '\srsthirdt3.png"}');
	c2= cats('^S={width=8.5cm just=center preimage="', "&png_dest", '\srsthirdt4.png"}');
	output;
run;

ods escapechar='^';


proc report data=combine nowindows style=[rules=none frame=void cellpadding=0]  list;
			columns c1 c2;
			define c1-c2 /display ' ';
run;

**This is from the log file:

 

PROC REPORT DATA=WORK.COMBINE LS=97 PS=54 SPLIT="/" CENTER ;
COLUMN ( c1 c2 );

DEFINE c1 / DISPLAY FORMAT= $150. WIDTH=150 SPACING=2 LEFT " " ;
DEFINE c2 / DISPLAY FORMAT= $150. WIDTH=150 SPACING=2 LEFT " " ;
RUN;

ERROR: The width of c1 is not between 1 and 97. Adjust the column width or line size.
NOTE: This affects LISTING output.

 

So, I try changing the length to 97 and get a different error with 'cats' function. Please see below:

 

 

WARNING: In a call to the CATS function, the buffer allocated for the result was not long enough to contain the concatenation of all the arguments. The correct result would contain 123 characters, but the actual result might either be truncated to 97 character(s) or be
completely blank, depending on the calling environment. The following note indicates the left-most argument that caused truncation.
NOTE: Argument 2 to function CATS('^S={width=8.'[12 of 38 characters shown],'''C:\Users\lm'[12 of 68 characters shown],'\srsthirdt1.'[12 of 17 characters shown]) at line 143 column 9 is invalid.

 

 

Do you think it is due to the location I'm saving the graphs at?

 

Thanks!

 

 

unison
Lapis Lazuli | Level 10

Try increasing the length back to be sure everything fits in the column and looks like you’re on Windows, change the / before every picture name to \

-unison
unison
Lapis Lazuli | Level 10

When you define your png_dest path macro variable, remove the ‘s wrapping it (refer to where I define my path)

-unison
sas_epi
Calcite | Level 5

I kept the 'back slash' as is in the code, I figured that it'd be a windows necessity. Tried removing the wrapper in the macro variable definition, no change in the errors.

When you create the 'combine' data set, what do you see in the file? I see the link to the location of the graph pasted on the columns. It seems to me that when I create the dataset, SAS wants me to have enough length for the column, but when I call 'proc report' it doesn't like that length and wants me to change it to a max of 97. So, 'proc report' is not able to take the link information and use it to get the .png file, maybe?

 

 

 

 

 

 

 

unison
Lapis Lazuli | Level 10

Do you have 2 proc reports in your code? Comment out the second one. Also if you could edit your post above and adjust as follows:

delete the code in the post, copy from your SAS editor, click the running man and paste your code there. This will preserve the formatting making it easier to read and debug.

 Capture.PNG

-unison
sas_epi
Calcite | Level 5

So sorry about that Unison ! I didn't know that I could post the code that way, Thanks !

 

I had commented out the 'proc report' that I wasn't using

unison
Lapis Lazuli | Level 10

Hey, not a problem! Okay so now that's great. Can you show me the log with your current code now? Also, just another question, have you made sure the png's are begin generated in the destination you specified?

-unison
sas_epi
Calcite | Level 5

The log file output is right below that code itself- it told me that width of column 1 needs to be between 1 and 97. I re ran the same code with length set to 97 and the error message changed to below. I'm copying and pasting directly from the log file ::

 

*********************************************************************************************************************************

NOTE: Argument 2 to function CATS('^S={width=8.'[12 of 38 characters shown],'C:\Users\lm3'[12 of 66 characters shown],'\srsthirdt3.'[12 of 17 characters shown]) at line 194 column 9 is invalid.


WARNING: In a call to the CATS function, the buffer allocated for the result was not long enough
to contain the concatenation of all the arguments. The correct result would contain 121
characters, but the actual result might either be truncated to 97 character(s) or be
completely blank, depending on the calling environment. The following note indicates
the left-most argument that caused truncation.
NOTE: Argument 2 to function CATS('^S={width=8.'[12 of 38 characters shown],'C:\Users\lm3'[12 of
66 characters shown],'\srsthirdt4.'[12 of 17 characters shown]) at line 195 column 9 is
invalid.
c1= c2= _ERROR_=1 _N_=1

 

**********************************************************************************************************************

 

When I have the length specified as 150, the link to the location of the graphs gets pasted on the columns of the 'combine' data set, and when I change the length to 97, that disappears -possibly coz the column is now too small . One of the first things I checked was to see if the graphs were being created and stored in the location that I specified, that part works.

unison
Lapis Lazuli | Level 10

can you show me what your combine dataset looks like when you provide length 150?

-unison
sas_epi
Calcite | Level 5
Hi ChrisNZ,
Thanks for the suggestion. I had unsuccessfully attempted both the options in that link before I posted on the forum. Unison's code helped me out!
Tom
Super User Tom
Super User

How is PROC REPORT producing that output when the only ODS destination you have active is LISTING?

unison
Lapis Lazuli | Level 10

I just realized this as well. I think when I originally put this together, I was running code step-wise. Added an ODS HTML statement to my solution.

 

Thanks,

-unison

-unison

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 14 replies
  • 2495 views
  • 2 likes
  • 4 in conversation