Usage Note 23978: How can I automate the creation of a COMPUTE
variable under an ACROSS variable?
You can automate the creation of the COMPUTE
variable under an ACROSS variable by using
MACRO processing.
Prior to PROC REPORT, sort the data set by the
ACROSS variable. In a DATA step, specify the data
set by the ACROSS variable and add FIRST.LOGIC to
create a counter to count the unique values of
the ACROSS variable. Use a CALL SYMPUT to create a
macro variable that will contain the counter value.
In the macro, create macro variables with a %let to
contain the column number of the first COMPUTED
variable under the ACROSS, the number of variables
before the ACROSS, and the number of variables
under the ACROSS. Use a MACRO %DO loop to create
the COMPUTE statements.
Here is an example of this technique.
DATA example;
INPUT flower $ color $ cost;
CARDS;
violet purple 3.50
violet pink 5.00
rose pink 8.50
rose purple 9.00
rose white 3.35
rose coral 7.50
;
RUN;
PROC SORT DATA=example;
BY color;
RUN;
DATA _NULL_;
SET example end = done;
BY color;
IF FIRST.color THEN count+1;
if done then
CALL SYMPUT('num',TRIM(LEFT(put(count,8.))));
RUN;
%MACRO across;
/* 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;
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;
%END;
ENDCOMP;
RUN;
%MEND;
%across
Operating System and Release Information
*
For software releases that are not yet generally available, the Fixed
Release is the software release in which the problem is planned to be
fixed.
Type: | Usage Note |
Priority: | low |
Topic: | SAS Reference ==> Procedures ==> REPORT
|
Date Modified: | 2007-12-17 11:14:42 |
Date Created: | 2004-05-14 13:45:31 |