%LET SMT=SMOOTHTHIS;

PROC IML;
    USE TESTVAR;
    READ ALL VAR{TESTVAR} INTO TESTVAR;

 

    USE TEMPNEW;
    READ ALL VAR{&RAW_SCR. COUNT OPTION0 OPTION1 OPTION2 OPTION3 OPTION4 /*OPTION8*/ OPTION9} INTO &SMT.;
        &SMT.Z=REPEAT(0, NROW(&SMT.), 8);
        &SMT.=&SMT.||&SMT.Z;

 

    /*DEFINITION OF THE KERNEL BANDWIDTH*/
    H=1.1*(SUM(&SMT.[,2])**-.2);

 

    /*COMPUTATION OF THE KERNEL SMOOTHING WEIGHTS.*/
    DO I=1 TO NROW(&SMT.);
        DO J=1 TO NROW(&SMT.);
            &SMT.[J,10]=EXP((-1/(2*H))*(&SMT.[J,1]-&SMT.[I,1])**2/TESTVAR)*&SMT.[J,2];
        END;

 

    /*USE OF THE KERNEL SMOOTHING WEIGHTS IN THE MOVING AVERAGE OF THE CONDITIONAL MEANS.*/
        DO K=1 TO NROW(&SMT.);
            DO Q=1 TO 6;
                &SMT.[I,10+Q]=&SMT.[I,10+Q]+(&SMT.[K,10]*&SMT.[K,Q+2])/SUM(&SMT.[,10]);
            END;
        END;
    END;

 

    /*EXPORTING THE RESULTS.*/
    CREATE KSOUT FROM &SMT.;
    APPEND FROM &SMT.;
QUIT;

 

PROC SQL NOPRINT;
CREATE TABLE KSOUT AS
SELECT COL1 AS &RAW_SCR., COL2 AS COUNT, 
   COL3 AS OPTION0, COL11 AS OPTION_KSED_0,
   COL4 AS OPTION1, COL12 AS OPTION_KSED_1,
   COL5 AS OPTION2, COL13 AS OPTION_KSED_2,
   COL6 AS OPTION3, COL14 AS OPTION_KSED_3,
   COL7 AS OPTION4, COL15 AS OPTION_KSED_4,
/*   COL8 AS OPTION8, COL16 AS OPTION_KSED_8,*/
   COL8 AS OPTION9, COL16 AS OPTION_KSED_9
FROM KSOUT;
QUIT;

 


PROC TRANSPOSE DATA = KSOUT 
OUT = KSOUT;
BY &RAW_SCR.;
VAR OPTION_KSED_0-OPTION_KSED_4 /*OPTION_KSED_8*/ OPTION_KSED_9;
RUN;

 

DATA KSOUT; SET KSOUT;
ITEM_&I. = INPUT(SUBSTR(_NAME_, 13, 1), 5.);
RENAME COL1 = KSMTHED_PERCENT;
DROP _NAME_;
RUN;

 

PROC SORT DATA = KSOUT;
BY ITEM_&I.;
RUN;

 

DATA KSOUT;
  SET KSOUT;
  BY ITEM_&I.;
  IF FIRST.ITEM_&I. THEN ID=0;
  ID+1;
  IF MOD(ID, 3) = 1 THEN LABEL=ITEM_&I.;
RUN;

