BookmarkSubscribeRSS Feed
NURAO
Obsidian | Level 7

PROC IML;
RESET NONAME;


START BP(A, LOWFEN, UPPFEN, LEFT, TRIMEAN) GLOBAL (NY,NTOT,WOBS,BOBS);
NTOT = NROW(A);
WOBS = NCOL(A);
BOBS = NCOL(NY);
YT = J(NTOT, WOBS, 0);
DOQ1 = J(1, NCOL(NY),0);
IDOQ1 = DOQ1;
DECIMAL = DOQ1;
Q1DIFF = DOQ1;
Q1DEC = DOQ1;
Q1 = J(1, NCOL(NY),0);
DOQ3 = DOQ1;
IDOQ3 = DOQ1;
DECIMAL3 = DOQ1;
Q3DIFF = DOQ1;
Q3DEC = DOQ1;
Q3 = Q1;
RMAD = Q1;
MADN = Q1;
LOWFEN = Q1;
UPPFEN = Q1;
LEFT = Q1;
NEWN = Q1;
HA = Q1;
TRIMEAN = J(1,NCOL(NY),0);
SS = Q1;
SM = Q1;
SEM = Q1;
F = 1;
M = 0;
DO I = 1 TO NCOL(NY);
SAMP = NY[I];
L = M+SAMP;

TEMP1 = A[F:L];
NV1 = TEMP1;
TEMP1[RANK(NV1),] = NV1;

YT = TEMP1;
DOQ1[,I]=(SAMP+1)/4;
IDOQ1[,I]=INT(DOQ1[,I]);
DECIMAL[,I]=DOQ1[,I]-IDOQ1[,I];
Q1DIFF[,I]=TEMP1[IDOQ1[,I]+1,1]- TEMP1[IDOQ1[,I],1];
Q1DEC[,I]=DECIMAL[,I]*Q1DIFF[,I];
Q1[,I]= TEMP1[IDOQ1[,I],1] + Q1DEC[,I];
DOQ3[,I]=(SAMP+1)*3/4;
IDOQ3[,I]=INT(DOQ3[,I]);
DECIMAL3[,I]=DOQ3[,I]-IDOQ3[,I];
Q3DIFF[,I]=TEMP1[IDOQ3[,I]+1,1]- TEMP1[IDOQ3[,I],1];
Q3DEC[,I]=DECIMAL3[,I]*Q3DIFF[,I];
Q3[,I]= TEMP1[IDOQ3[,I],1] + Q3DEC[,I];


RMAD[,I]=MAD(TEMP1,"MAD");
MADN[,I]=MAD(TEMP1,"NMAD");
LOWFEN[,I]=Q1[,I]-(1.44*MADN[,I]);
UPPFEN[,I]=Q3[,I]+(1.44*MADN[,I]);
LEFT=TEMP1[LOC(LOWFEN[,I]<TEMP1 & TEMP1<UPPFEN[,I])];
NEWN=NROW (LEFT);
HA=NEWN;
TRIMEAN[,I]=SUM(LEFT)/HA;
SS=VAR(LEFT);
SM=STD(LEFT);
SEM=SM;

NAMES={'GROUP1' 'GROUP2' 'GROUP3'};
M=L;
F=F + NY[I];
*PRINT LEFT;
*PRINT "SORT DATA" YT;
*PRINT YT;

END;
*PRINT "ORI DATA" A;
*PRINT "DEPTH OF Q3" DOQ3;
*PRINT IDOQ3;
*PRINT DECIMAL3;
*PRINT Q3DIFF;
*PRINT "DEC Q3" Q3DEC;
*PRINT "Q3=" Q3;
*PRINT "RMAD" RMAD;
*PRINT MADN;


*PRINT "QUARTILE=" Q;
*PRINT "Q1=" Q1;
*PRINT "LOWER FENCE" LOWFEN;
*PRINT "BOXPLOT TRIMMEAN = " TRIMEAN;
*PRINT TRIMEAN[COLNAME=NAMES];
*PRINT NY[COLNAME=NAMES];
*PRINT YT;
FINISH;


***MENJANA SAMPEL BUTSTRAP UNTUK PENGIRAAN RALAT PIAWAI PENGANGGAR
MOM **;
START BOOTDAT(A, TRIMEAN, YB) GLOBAL(NY, NTOT, WOBS, BOBS, SEED);

F = 1;
M = 0;
DO J = 1 TO BOBS;
L = M+NY[J];
TEMP = A[F:L,];
BVAL = TEMP;
DO P = 1 TO NROW(TEMP);
RVAL = UNIFORM(SEED);
BVAL[P,] = TEMP[CEIL(NROW(TEMP)#RVAL),];
END; **DO P**;
IF J = 1 THEN YB = BVAL;
ELSE YB = YB//BVAL;
M = L;
F = F + NY[J];
END; **DO J**;

***** PEMUSATAN DATA BUTSTRAP *****************;
F = 1;
M = 0;
DO I = 1 TO BOBS;
L = M + NY[I];
MVAL = TRIMEAN[,I];
DO K = F TO L BY 1;
YB[K,] = YB[K,] - MVAL;
END; **DO K**;
M = L;
F = F + NY[I];
END; ** DO I**;
FINISH;


START BOOTSTAT(YB, TRIMEANB) GLOBAL (NY, NTOT, WOBS, BOBS, SEED);
CALL BP(AB, LOWFENB, UPPFENB, LEFTB, TRIMEANB);
FINISH;

************* PENGIRAAN RALAT PIAWAI ********************;
START SEBOXPLOT;
CALL BP(A, LOWFEN, UPPFEN, LEFT, TRIMEAN);
F = 1;
M = 0;
DO BOOTLOOP = 1 TO NUMSIM;
CALL BOOTDAT(A, TRIMEAN, YB);
CALL BOOTSTAT(YB, TRIMEANB);
IF BOOTLOOP = 1 THEN TMEANB = TRIMEANB;
ELSE TMEANB = TMEANB//TRIMEANB;
END; **DO BOOTLOOP**;

VAR=J(1, BOBS, 0);
SE=J(1,BOBS,0);
DO I=1 TO BOBS;
VAR[,I]=(SSQ(TMEANB[,I])-(SUM(TMEANB[,I])**2/NUMSIM))/(NUMSIM-1);
SE[,I]=SQRT(VAR[,I]);

END;

PRINT "BOOTSTRAP STANDARD ERROR=" SE;


FINISH;

*/


**BILANGAN SAMPEL BUTSTRAP**;
NUMSIM = 50;
**SEED UTK BUTSTRAP**;
SEED = 40389;

********cubaan menggunakan data yg dijana*******;

NY = {11 11 11};

A = {5,8,7,3,9,4,3,29,5,6,7,
3,2,6,4,14,4,7,6,9,3,4,
9,9,8,7,10,11,27,12,15,17,16};

RUN SEBOXPLOT;

*CALL BP(A, LOWFEN, UPPFEN, LEFT, TRIMEAN);

 

QUIT;

 

 

Hi everyone,

 

I currently unable figure out what went wrong with code 'YT'. When I run the program, it stated that 'YT' was invalid operand to operation. Because of that I stuck to get 'BOOTSTRAP STANDARD ERROR'. Any help would greatly appreciated.

3 REPLIES 3
Rick_SAS
SAS Super FREQ

The definition of BOOTSTAT is invalid.

 

START BOOTSTAT(YB, TRIMEANB) GLOBAL (NY, NTOT, WOBS, BOBS, SEED);
CALL BP(AB, LOWFENB, UPPFENB, LEFTB, TRIMEANB);
FINISH;

 

The arguments in RED are not defined, so BP cannot process that call.

NURAO
Obsidian | Level 7

If you dont mine to answer, where should I define them.

Rick_SAS
SAS Super FREQ

I don't know. The program does not make sense because the arguments are invalid.

 

Here is a suggestion. The BOOTSTAT module does not do anything except call BP. Therefore in the SEBOXPLOT module, you should be able to replace the call to BOOTSTAT with a call to BP. However, I don't know what arguments you would need to use inside the DO BOOTLOOP loop.

 

It looks like you are doing a bootstrap analysis. You might want to look at my blog posts about how to bootstrap in SAS. I have several that use PROC IML to bootstrap. You can use your favorite search engine to search for 

bootstrap "proc iml" site:https://blogs.sas.com/content/iml

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 3 replies
  • 1460 views
  • 0 likes
  • 2 in conversation