I want to apply a pre-defined format to several columns, but only for one variable. The problem is, this variable has two subgroups, LEFT and RIGHT, my codes only change the format for the first subgroup - Left, but not the second one - Right. I want to apply the same format to the second subgroup - Right.
Here is my code:
DATA have;
INPUT subject $ variable $ parameter $ V1-V6;
DATALINES;
A-001 qAF Left 1 2 3 4 5 6
A-001 qAF Right 1 2 3 4 5 6
A-001 Cortical Left 1 1 1 1 1 1
A-001 Cortical Right 1 2 1 1 1 1
A-001 Posterial Left 1 1 1 2 1 1
A-001 Posterial Right 1 1 1 1 1 3
;
RUN;
PROC FORMAT;
VALUE cort
1 = 'C1'
2 = 'C2';
RUN;
PROC REPORT DATA = have;
COLUMNS subject variable parameter V1 V2 V3 V4 V5 V6 dummy;
DEFINE subject / ORDER;
DEFINE variable / ORDER;
DEFINE dummy / COMPUTED NOPRINT;
COMPUTE dummy;
IF variable = 'Cortical' THEN DO;
DO i = 4 TO 9;
CALL DEFINE (i, 'format', 'cort.');
END;
END;
ENDCOMP;
COMPUTE AFTER variable;
LINE ' ';
ENDCOMP;
OPTIONS missing = '';
RUN;
You need to HOLD the value of VARIABLE. See COMPUTE BEFORE.
PROC REPORT DATA = have;
COLUMNS subject variable parameter V1 V2 V3 V4 V5 V6 dummy;
DEFINE subject / ORDER;
DEFINE variable / ORDER;
DEFINE dummy / COMPUTED NOPRINT;
compute before variable;
hold=variable;
endcomp;
COMPUTE dummy;
IF hold = 'Cortical' THEN DO;
DO i = 4 TO 9;
CALL DEFINE (i, 'format', 'cort.');
END;
END;
ENDCOMP;
COMPUTE AFTER variable;
LINE ' ';
ENDCOMP;
OPTIONS missing = '';
RUN;