BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
smackerz1988
Pyrite | Level 9

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 

smackerz1988_0-1701769368126.png

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);

smackerz1988_0-1701769771532.png

 

 

Any help on this matter would be greatly appreciated

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
SASJedi
SAS Super FREQ

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.

 

 

Check out my Jedi SAS Tricks for SAS Users

View solution in original post

2 REPLIES 2
SASJedi
SAS Super FREQ

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.

 

 

Check out my Jedi SAS Tricks for SAS Users
smackerz1988
Pyrite | Level 9

@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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 2 replies
  • 448 views
  • 3 likes
  • 2 in conversation