Hello,
I'm trying to use this macro
%MACRO dtt_compare_figure(infile1=, infile2=, outfile=);
FILENAME cmd8295 TEMP;
DATA _NULL_;
FILE cmd8295 LRECL=500;
PUT 'PROC GROOVY; ';
PUT ' SUBMIT "&infile1" "&infile2" "&outfile"; ';
PUT ' import java.awt.image.BufferedImage; ';
PUT ' import java.awt.Color; ';
PUT ' import javax.imageio.ImageIO; ';
PUT ' ';
PUT ' final int RED_COLOR = new Color(255, 0, 0).getRGB(); ';
PUT ' ';
PUT ' String image1 = args[0]; ';
PUT ' String image2 = args[1]; ';
PUT ' String out = args[2]; ';
PUT ' ';
PUT ' System.out.println("Compare picture " + image1); ';
PUT ' ';
PUT ' File fileImage1 = new File(image1); ';
PUT ' File fileImage2 = new File(image2); ';
PUT ' File fileOut = new File(out); ';
PUT ' ';
PUT ' BufferedImage img1=null; ';
PUT ' BufferedImage img2=null; ';
PUT ' img1 = ImageIO.read(fileImage1); ';
PUT ' img2 = ImageIO.read(fileImage2); ';
PUT ' ';
PUT ' int pixelDiff = 0; ';
PUT ' if (img1.getWidth() == img2.getWidth() && img1.getHeight() == img2.getHeight()) { ';
PUT ' for (int x = 0; x < img1.getWidth(); x++) { ';
PUT ' for (int y = 0; y < img1.getHeight(); y++) { ';
PUT ' if (img1.getRGB(x, y) != img2.getRGB(x, y)) { ';
PUT ' pixelDiff++; ';
PUT ' img2.setRGB(x, y, RED_COLOR); ';
PUT ' } ';
PUT ' } ';
PUT ' } ';
PUT ' } else { ';
PUT ' System.out.println("ERROR: Height and/or Weight for both images are not equal."); ';
PUT ' return; ';
PUT ' } ';
PUT ' if (pixelDiff != 0) { ';
PUT ' System.out.println("WARNING: " + pixelDiff + " changes found for " + image1); ';
PUT ' ImageIO.write(img2, "png", fileOut); ';
PUT ' } else { ';
PUT ' System.out.println("No changes found: " + image1); ';
PUT ' } ';
PUT ' ENDSUBMIT; ';
PUT 'QUIT; ';
RUN;
%INCLUDE cmd8295;
FILENAME cmd8295;
%MEND dtt_compare_figure;
%dtt_compare_figure(
infile1 = &dir/&filename1..png,
infile2 = &dir/&filename2..png,
outfile = &dir/&filename_out..png
);
I have directed infile1 and infile2 to the correct file locations but I keep getting this error no matter what examples I try to use
I'm using SAS EG on a remote server but when I use more simple PROC GROOVY code it works fine such as this
%MACRO sayHello(name);
FILENAME cmdFile TEMP;
DATA _NULL_;
FILE cmdFile LRECL=500;
PUT 'PROC GROOVY; ';
PUT ' SUBMIT "&name"; ';
PUT ' String name = args[0]; ';
PUT ' System.out.println("Hello " + name + "!");';
PUT ' ENDSUBMIT; ';
PUT 'QUIT; ';
RUN;
%INCLUDE cmdFile;
%MEND sayHello;
%sayHello(Stephen);
Any help on this matter would be greatly appreciated
From your log, it looks like the SAS system can't read the image file KMEDirect.png. I'm assuming you already opened the image file in a viewer to ensure it's not corrupted. I compiled your macro, then ran these two calls to test it:
%let dir=c:/temp;
%let filename1=picture1.png;
%let filename2=picture2.png;
%let filename_out=picture_out.png;
%dtt_compare_figure(
infile1 = &dir/&filename1,
infile2 = &dir/&filename2,
outfile = &dir/&filename_out
);
With this result:
MPRINT(DTT_COMPARE_FIGURE): PROC GROOVY; MPRINT(DTT_COMPARE_FIGURE): SUBMIT "c:/temp/picture1.png" "c:/temp/picture2.png" "c:/temp/picture_out.png"; Compare picture c:/temp/picture1.png No changes found: c:/temp/picture1.png NOTE: The SUBMIT command completed. MPRINT(DTT_COMPARE_FIGURE): QUIT; NOTE: PROCEDURE GROOVY used (Total process time): real time 0.05 seconds cpu time 0.00 seconds
And this call:
%let filename3=picture3.png;
%let filename13_out=picture13_out.png;
%dtt_compare_figure(
infile1 = &dir/&filename1,
infile2 = &dir/&filename3,
outfile = &dir/&filename13_out
);
with this result:
MPRINT(DTT_COMPARE_FIGURE): PROC GROOVY; MPRINT(DTT_COMPARE_FIGURE): SUBMIT "c:/temp/picture1.png" "c:/temp/picture3.png" "c:/temp/picture13_out.png"; Compare picture c:/temp/picture1.png ERROR: Height and/or Weight for both images are not equal. NOTE: The SUBMIT command completed. MPRINT(DTT_COMPARE_FIGURE): QUIT; NOTE: PROCEDURE GROOVY used (Total process time): real time 0.02 seconds cpu time 0.01 seconds
So the macro seems to be working. I'm attaching a ZIP file with the images I used for testing. Try running the same macro calls I ran against the images I provided. If that works for you, your original image files may not be readable from your SAS session.
From your log, it looks like the SAS system can't read the image file KMEDirect.png. I'm assuming you already opened the image file in a viewer to ensure it's not corrupted. I compiled your macro, then ran these two calls to test it:
%let dir=c:/temp;
%let filename1=picture1.png;
%let filename2=picture2.png;
%let filename_out=picture_out.png;
%dtt_compare_figure(
infile1 = &dir/&filename1,
infile2 = &dir/&filename2,
outfile = &dir/&filename_out
);
With this result:
MPRINT(DTT_COMPARE_FIGURE): PROC GROOVY; MPRINT(DTT_COMPARE_FIGURE): SUBMIT "c:/temp/picture1.png" "c:/temp/picture2.png" "c:/temp/picture_out.png"; Compare picture c:/temp/picture1.png No changes found: c:/temp/picture1.png NOTE: The SUBMIT command completed. MPRINT(DTT_COMPARE_FIGURE): QUIT; NOTE: PROCEDURE GROOVY used (Total process time): real time 0.05 seconds cpu time 0.00 seconds
And this call:
%let filename3=picture3.png;
%let filename13_out=picture13_out.png;
%dtt_compare_figure(
infile1 = &dir/&filename1,
infile2 = &dir/&filename3,
outfile = &dir/&filename13_out
);
with this result:
MPRINT(DTT_COMPARE_FIGURE): PROC GROOVY; MPRINT(DTT_COMPARE_FIGURE): SUBMIT "c:/temp/picture1.png" "c:/temp/picture3.png" "c:/temp/picture13_out.png"; Compare picture c:/temp/picture1.png ERROR: Height and/or Weight for both images are not equal. NOTE: The SUBMIT command completed. MPRINT(DTT_COMPARE_FIGURE): QUIT; NOTE: PROCEDURE GROOVY used (Total process time): real time 0.02 seconds cpu time 0.01 seconds
So the macro seems to be working. I'm attaching a ZIP file with the images I used for testing. Try running the same macro calls I ran against the images I provided. If that works for you, your original image files may not be readable from your SAS session.
@SASJedi Thank you so much! I believe the issue is the current read-write permission with the temporary cmdfile that is masking the proc groovy code. I have followed up with IT.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Early bird rate extended! Save $200 when you sign up by March 31.
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.
Ready to level-up your skills? Choose your own adventure.