options pagesize = 32767;

data scaleImage;

   xscreen = 1280;
   yscreen = 1024;

   xmax = int(.75 * xscreen); 
   ymax = int(.75 * yscreen);

   do pfactor = .125, 1, 8;
	   do ximage = 10, 100, 1000, 10000, 100000;
	      do yimage = 10, 100, 1000, 10000, 100000;

	         if ximage * yimage <= 2 ** 32 then do;

	            if ximage > xmax or yimage > ymax then do;
	               xfactor = xmax / ximage;
						yfactor = ymax / yimage;
						factor = min(xfactor, yfactor);
				   	if factor < 1 / 16 then
				      	factor = min(max(xfactor, yfactor, 1 / 16), pfactor);
						factor = max(factor, 1 / ximage, 1 / yimage);
					end; /* if ximage > xmax or yimage > ymax */

	            else do; xfactor = 1; yfactor = 1; factor = 1; end;

	            if factor > 1 then do; numerator = int(factor); denominator = 1; end;
					else do; numerator = 1; denominator = ceil(1 / factor); end;
					factor = numerator / denominator;

					xscaled = int(ximage * factor);
					yscaled = int(yimage * factor);

					xwindow = min(xmax, xscaled);
					ywindow = min(ymax, yscaled);

					xfraction = xwindow / xscreen;
					yfraction = ywindow / yscreen;

					if xscaled > xmax then xscroll = 'YES'; else xscroll = 'NO ';
					if yscaled > ymax then yscroll = 'YES'; else yscroll = 'NO ';

					output;

				end; /* if ximage * yimage <= 2 **32 */

	      end; /* do yimage=... */
	   end; /* do ximage=... */
   end; /* do pfactor=... */

   label xscreen = "Horizontal Screen Resolution"
			yscreen = "Vertical Screen Resolution"
			pfactor = "Previous Scale Factor"
			ximage = "Horizontal Image Size"
			yimage = "Vertical Image Size"
			numerator = "Scale Factor Numerator"
			denominator = "Scale Factor Denominator"
			factor = "Effective Scale Factor"
			xscaled = "Horizontal Scaled Image Size"
			yscaled = "Vertical Scaled Image Size"
      	xwindow = "Horizontal Window Size"
			ywindow = "Vertical Window Size"
			xfraction = "Horizontal Window Fraction"
			yfraction = "Vertical Window Fraction"
			xscroll = "Horizontal Scrolling Required"
			yscroll = "Vertical Scrolling Required"
			;

   format xfraction yfraction percent6.0;

run;


proc print data=scaleImage label split=' ';
   by xscreen yscreen pfactor;
   id ximage yimage;
   var numerator denominator factor xscaled yscaled xwindow ywindow xfraction yfraction xscroll yscroll;
run;


