Hi,
Please see the below for my data:
data temp;
input ID $ score section;
datalines;
1 90 1
1 89 1
1 92 1
1 70 2
1 65 2
1 80 2
1 88 3
1 70 3
1 75 3
2 95 1
2 88 1
2 93 1
2 87 2
2 83 2
2 70 2
***more data;
;
run;
I want to get the plot of score by section for each ID, that is,one page for each ID, and draw a line to label the mean. I have many many IDs so I used a macro to do it. Here is my code:
%macro test(id);
data temp2;
set temp;
if ID="&id";
run;
PROC MEANS DATA=temp2 NOPRINT N MEAN STD;
VAR score;
CLASS section;
OUTPUT OUT=summary N=TOT MEAN=mean_score STD=std_score;
RUN;
data summary2;
set summary;
if section='' then delete;
run;
proc sort data=summary2;
by section;
run;
DATA _NULL_;
SET summary2;
CALL SYMPUT('a'!!TRIM(LEFT(_N_)),mean_score);
RUN;
DATA anno_data;
%SYSTEM(2,2);
%ANNOMAC;
%LINE(0.7,&a1,1.3,&a1,BLACK,1,4);
%LINE(1.7,&a2,2.3,&a2,BLACK,1,4);
%LINE(2.7,&a3,3.3,&a3,BLACK,1,4);
RUN;
AXIS1 ORDER=(0 TO 4 BY 1);
PROC GPLOT DATA=temp2 ANNO=anno_data;
PLOT score*section / haxis=axis1;
RUN;
QUIT;
%mend;
%test(1);
%test(2);
The first plot (ID=1) is correct. For ID=2, the data doesn't have section 3, but sas still draw a line at y=77.6, I guess this is the mean for a3 when ID=1, so it seemed it passed the value of last run. I don't understand how this happen. Thanks in advance.
Lu