The macro operates on internal macro variables (`&hsize`, `&vsize`, `&hpos`, `&vpos`), which are either initialized by the SAS environment or defined by a prerequisite macro (%gask). The data processed are numerical values calculated within a `DATA _NULL_` step, without reading external datasets or the SASHELP library. The results of the calculations are then stored in macro variables via `call symput`.
1 Code Block
Macro Call
Explanation : This call to the `%gask` macro (whose definition is not provided in this script) is used to retrieve the current values of the `hsize`, `vsize`, `hpos`, and `vpos` macro variables in the SAS environment. These values are essential for subsequent calculations to ensure that resizing is based on the current state of the graphic options.
Copied!
%gask(unit=&unit);
1
%gask(unit=&unit);
2 Code Block
DATA STEP
Explanation : This `DATA _NULL_` step is the core of the resizing logic. It calculates the horizontal (`hcell`), vertical (`vcell`) cell sizes and their aspect ratio (`acell`). Conditional logic determines how `hsize` and `vsize` should be adjusted based on the `h` and `v` inputs. The `hpos` and `vpos` values are then recalculated to maintain the aspect ratio after the size change. Finally, `call symput` is used to update the global macro variables `hsize`, `vsize`, `hpos`, and `vpos` with the new values, making them available for subsequent SAS statements. Debugging information is displayed if the `verbose` parameter is enabled.
Copied!
data _null_;
h=&h;
v=&v;
hcell = &hsize / &hpos; %*-- size of horizontal cell;
vcell = &vsize / &vpos; %*-- size of vertical cell;
acell = hcell / vcell; %*-- cell aspect ratio;
verbose = &verbose;
if verbose then put hcell= vcell= acell=;
if h=. or h=&hsize then do;
if v=. or v=&vsize then do;
*-- nothing has changed;
goto done;
end;
else do;
*-- only vsize has changed;
vsize = v;
hsize = &hsize;
end;
end;
else do;
*-- hsize has changed;
if v=. or v=&vsize then do;
*-- only hsize has changed;
hsize = h;
vsize = &vsize;
end;
else do;
*-- both hsize, vsize have changed;
hsize = h;
vsize = v;
end;
end;
* hpos = round(&hpos * (&vsize / vsize));
* vpos = round(&vpos * (&hsize / hsize));
hpos = round(&hpos * (&hsize / hsize));
vpos = round(&vpos * (&vsize / vsize));
call symput('hsize', compress(put(hsize,best6.2)));
call symput('vsize', compress(put(vsize,best6.2)));
call symput('hpos', compress(put(hpos,3.)));
call symput('vpos', compress(put(vpos,3.)));
if verbose then do;
put hsize= vsize= hpos= vpos=;
hcell = hsize / hpos;
vcell = vsize / vpos;
acell = hcell / vcell;
put hcell= vcell= acell=;
end;
done:
run;
1
DATA _null_;
2
h=&h;
3
v=&v;
4
hcell = &hsize / &hpos; %*-- size of horizontal cell;
5
vcell = &vsize / &vpos; %*-- size of vertical cell;
Explanation : This `goptions` statement applies the `hsize`, `vsize`, `hpos`, and `vpos` values that were calculated and updated in the `DATA _NULL_` step. It thus defines the new dimensions and positioning of the graph using the specified unit, ensuring that the graph is displayed with the corrected aspect ratio.
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.