Sample 25093: In PROC REPORT , COMPUTE statements for a COMPUTED variable under an ACROSS when the number of columns is unknown
See the Full Code tab and the Results tab for details.
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
DATA example;
INPUT flower $ color $ cost;
DATALINES;
violet purple 3.50
violet pink 5.00
rose pink 8.50
rose purple 9.00
rose white 3.35
rose coral 7.50
;
PROC SORT DATA=example;
BY color;
RUN;
DATA _NULL_;
SET example;
BY color;
IF FIRST.color THEN count+1;
CALL SYMPUT('num',TRIM(LEFT(count)));
RUN;
%MACRO doit;
/* The position of the first computed var under the across */
%LET startcol=3;
/* The number of vars before the across */
%LET varsleft=1;
/* Number of values under the across */
%LET varsunder=2;
ods html file='myhtm.htm';
PROC REPORT DATA=example NOWD list ls=100;
COL flower color,(cost sale);
DEFINE flower / GROUP;
DEFINE color / ACROSS;
DEFINE cost / SUM FORMAT=DOLLAR8.2;
DEFINE sale / COMPUTED FORMAT=DOLLAR8.2;
COMPUTE sale;
%DO i=&startcol %TO %EVAL(&num*&varsunder+&varsleft) %BY &varsunder;
_C%EVAL(&i)_=_C%EVAL(&i-1)_*10;
if _C%eval(&i)_ > 45 then call define("_C%eval(&i)_",'style','style=[background=yellow]');
%END;
ENDCOMP;
RUN;
ods html close;
%MEND;
%doit
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
Create a macro variable with CALL SYMPUT that contains the unique
number of values for the ACROSS variable. Create macro variables for
postion of the crossing. Then use a MACRO do loop to create the
COMPUTED variable statements.
| Type: | Sample |
| Topic: | SAS Reference ==> Macro SAS Reference ==> Procedures ==> REPORT
|
| Date Modified: | 2005-08-27 03:03:14 |
| Date Created: | 2005-01-26 16:18:11 |
Operating System and Release Information
| SAS System | Base SAS | All | 8 TS M0 | n/a |