/*Rasch BOOTSTRAP PROGRAM*/ /*VERSION 1.0*/ /*ERIC, GEORGE, & KAZ*/ /*basic speficication*/ %let mainfolder=G:\EricRasch\KazPROGRAM\rate5B\;/*must end with a backward slash*/ %let win= C:\WINSTEPS\WINSTEPS.EXE; /*SPECIFIC TO EACH RUN*/ %let scale=rate5; /*the name of your outcome*/ %let codes=012345; /*what are the codes now?*/ %let rc=15; /*no of recategorizations--must match the N of rows in the GOWINSTEP part below*/ %let ni =27; /*n of items -- must match the N of items in the data below*/ %let bt=500; /*no of bootstraps -- this can vary by your purpose*/ /*Don't change this*/ option noxwait xsync; /*MODIFY HERE for different specification of Winstep runs*/ %macro GOWINSTEP; x "START /WAIT &win BATCH=YES &WD&scale..con &WD&scale.1.out data=&storage.&scale.B&i..dat NEWSCORE=11112 xfile=&XF.rc1b&i..xf "; x "START /WAIT &win BATCH=YES &WD&scale..con &WD&scale.2.out data=&storage.&scale.B&i..dat NEWSCORE=11122 xfile=&XF.rc2b&i..xf "; x "START /WAIT &win BATCH=YES &WD&scale..con &WD&scale.3.out data=&storage.&scale.B&i..dat NEWSCORE=11123 xfile=&XF.rc3b&i..xf "; x "START /WAIT &win BATCH=YES &WD&scale..con &WD&scale.4.out data=&storage.&scale.B&i..dat NEWSCORE=11222 xfile=&XF.rc4b&i..xf "; x "START /WAIT &win BATCH=YES &WD&scale..con &WD&scale.5.out data=&storage.&scale.B&i..dat NEWSCORE=11223 xfile=&XF.rc5b&i..xf "; x "START /WAIT &win BATCH=YES &WD&scale..con &WD&scale.6.out data=&storage.&scale.B&i..dat NEWSCORE=11233 xfile=&XF.rc6b&i..xf "; x "START /WAIT &win BATCH=YES &WD&scale..con &WD&scale.7.out data=&storage.&scale.B&i..dat NEWSCORE=11234 xfile=&XF.rc7b&i..xf "; x "START /WAIT &win BATCH=YES &WD&scale..con &WD&scale.8.out data=&storage.&scale.B&i..dat NEWSCORE=12222 xfile=&XF.rc8b&i..xf "; x "START /WAIT &win BATCH=YES &WD&scale..con &WD&scale.9.out data=&storage.&scale.B&i..dat NEWSCORE=12223 xfile=&XF.rc9b&i..xf "; x "START /WAIT &win BATCH=YES &WD&scale..con &WD&scale.10.out data=&storage.&scale.B&i..dat NEWSCORE=12233 xfile=&XF.rc10b&i..xf "; x "START /WAIT &win BATCH=YES &WD&scale..con &WD&scale.11.out data=&storage.&scale.B&i..dat NEWSCORE=12234 xfile=&XF.rc11b&i..xf "; x "START /WAIT &win BATCH=YES &WD&scale..con &WD&scale.12.out data=&storage.&scale.B&i..dat NEWSCORE=12333 xfile=&XF.rc12b&i..xf "; x "START /WAIT &win BATCH=YES &WD&scale..con &WD&scale.13.out data=&storage.&scale.B&i..dat NEWSCORE=12334 xfile=&XF.rc13b&i..xf "; x "START /WAIT &win BATCH=YES &WD&scale..con &WD&scale.14.out data=&storage.&scale.B&i..dat NEWSCORE=12344 xfile=&XF.rc14b&i..xf "; x "START /WAIT &win BATCH=YES &WD&scale..con &WD&scale.15.out data=&storage.&scale.B&i..dat NEWSCORE=12345 xfile=&XF.rc15b&i..xf "; %mend GOWINSTEP; /*YOUR DATA HERE--with no ID please*/ data &scale;input @1 (item1-item&ni) (&ni*1.);cards; 133233223222312232332111222 122233332333422223442212332 133344443343421223322232344 132233223332422222222233433 133333322333422433322223333 143233322323423443333223333 101323322210401211000001232 142244433423432332433332344 144244344343432242223332323 133233222222322223321122333 133344444322423334442223333 144444443443432334442244444 133333333333433322222223333 121122221212302333230001222 133244234432312231211111222 043334444333433344443344444 044444444443444444444344443 044444244423442332330100212 023332322232322232331123443 044444444443434444433223444 043344333432332343332323323 044343234422314342223224333 042244333322421343320011111 043344334442413332332122423 032322333213331232221123322 034443444433424444342242444 044344344433444233234433333 032232322443322221221122322 032233323333332222221112222 043344444443413344442223321 ; run; /*STOP HERE*//*STOP HERE*//*STOP HERE*//*STOP HERE*/ /*STOP HERE*//*STOP HERE*//*STOP HERE*//*STOP HERE*/ /*STOP HERE*//*STOP HERE*//*STOP HERE*//*STOP HERE*/ /*STOP HERE*//*STOP HERE*//*STOP HERE*//*STOP HERE*/ /*writing macro statements to a C temp folder.*/ data program;input write $ 1-22 read $ 25-44 RC $ 45-50; datalines4; %writebootgen(RC1); %readbootgen(RC1); RC1z %writebootgen(RC2); %readbootgen(RC2); RC2z %writebootgen(RC3); %readbootgen(RC3); RC3z %writebootgen(RC4); %readbootgen(RC4); RC4z %writebootgen(RC5); %readbootgen(RC5); RC5z %writebootgen(RC6); %readbootgen(RC6); RC6z %writebootgen(RC7); %readbootgen(RC7); RC7z %writebootgen(RC8); %readbootgen(RC8); RC8z %writebootgen(RC9); %readbootgen(RC9); RC9z %writebootgen(RC10); %readbootgen(RC10); RC10z %writebootgen(RC11); %readbootgen(RC11); RC11z %writebootgen(RC12); %readbootgen(RC12); RC12z %writebootgen(RC13); %readbootgen(RC13); RC13z %writebootgen(RC14); %readbootgen(RC14); RC14z %writebootgen(RC15); %readbootgen(RC15); RC15z %writebootgen(RC16); %readbootgen(RC16); RC16z %writebootgen(RC17); %readbootgen(RC17); RC17z %writebootgen(RC18); %readbootgen(RC18); RC18z %writebootgen(RC19); %readbootgen(RC19); RC19z %writebootgen(RC20); %readbootgen(RC20); RC20z ;;;; run; data program;set program; jun=_n_; if jun <= &rc; run; data _null_;set program; file "c:\temp\macro write for &scale..txt"; put (write) (100.0); run; data _null_;set program; file "c:\temp\macro read for &scale..txt"; put (read) (100.0); run; data _null_;set program; file "c:\temp\macro rc for &scale..txt"; put (RC) (100.0); run; /*This is to create a list of items*/ data program2;input itemlist $ 1-15; datalines4; %let itemlist= item1 item2 item3 item4 item5 item6 item7 item8 item9 item10 item11 item12 item13 item14 item15 item16 item17 item18 item19 item20 item21 item22 item23 item24 item25 item26 item27 item28 item29 item30 ;;;; run; data program2;set program2; jun=_n_; if jun <= (&ni+1); run; data xxx; itemlist=";"; run; data program2; set program2 xxx;run; data _null_;set program2; file "c:\temp\macro itemlist for &scale..txt"; put (itemlist) (20.0); run; %include "c:\temp\macro itemlist for &scale..txt"; /*this is for creating a list of items--to be used in a Winstep syntax*/ data _null_;set program2; jun2=(&ni+1); if jun ne 1; if itemlist = ";" then itemlist="ENDNAMES"; file "c:\temp\macro itemlist2 for &scale..txt"; put (itemlist) (20.0); run; /*create folders. If already exist, it doesn't create any problems.*/ x "mkdir &mainfolder.&scale"; x "mkdir &mainfolder.&scale.\Xfiles"; x "mkdir &mainfolder.&scale.\Xfiles\Other"; x "mkdir &mainfolder.&scale.\BootGenErrorFiles"; x "mkdir &mainfolder.&scale.\CatGenErrorFile"; x "mkdir &mainfolder.&scale.\CatGenErrorFile\boot1to100"; /*lots of folder statements*/ %let direc=&mainfolder.&scale.\Xfiles\Other\; %let WD=&direc; %let XF=&mainfolder.&scale.\Xfiles\; libname herex "&direc" ; %let storage=&mainfolder.&scale.\; libname here "&mainfolder.&scale.\BootGenErrorFiles"; libname here2 "&mainfolder.&scale.\CatGenErrorFile"; libname here3 "&mainfolder.&scale.\CatGenErrorFile\boot1to100"; /*log file wil be saved at this folder*/ proc printto log="&mainfolder.&scale\winsteplog.txt" new; run; %MACRO boot(nr=1,rbfile=r); %Do i=1 %to &nr; data &rbfile&i; choice = INT(RANUNI(0)*n)+1; SET &scale POINT = choice NOBS = n; PUT "RECORD= " 'RANDOM NUMBER = 'choice; j+1; IF j > n THEN STOP; *drop i j; drop j; RUN; %end; %mend; %boot (nr=&bt,rbfile=B); /* %boot (nr=%bt, rbfile=B); for when automating */ %macro eric (var1=); data &var1; set &var1; length resample $ 3; resample="&var1"; ID=_n_; run; %mend eric; %macro manyeric(howmany); %Do i=1 %to &howmany; %eric (var1=B&i); run; %end; %mend manyeric; %manyeric(&bt); *****************************************************************************; *****************************************************************************; %macro eric (dataname=); data &scale;set &dataname; /*women have DIF for these items, so treat them separately*/ /*instrumental variable to create a blank (maybe I don't really need this)*/ blank=' '; run; data &scale;set &scale; file "&storage.&scale.&dataname..dat"; put /* was (ID) (4.0) in LSF - this may have knock on effects down below!! */ (ID) (4.0) (blank)(1.0) (resample) (3.0) ( &itemlist ) (1.0); run; %mend eric; %macro manydataname(howmany); %Do i=1 %to &howmany; %eric (dataname=B&i); run; %end; %mend manydataname; %manydataname(&bt); /*these are lables for variables, which will come, in the WINSTEP control file, in between END and END NAMES*/ /* CHANGE put " item1=8" when you use no's larger then 999! */ filename new "c:\temp\first.txt"; data _null_; file new; put '&inst '; put "item1=9"; put "name1=1"; put "ni=&ni"; put "HLINES=n"; put ";target=y"; put ";table="; put "person=kid"; put "item=question"; put "codes=&codes"; put "udecim=6"; put ";pfile=&scale..pfile"; put ";ifile=&scale..ifile"; put "csv=n"; put "data=&WD&scale..dat"; put '&end'; run; filename stud1 "c:\temp\first.txt"; data first ;infile stud1 length=lg;input @;input @1 eachline $varying700. lg; run; filename stud2 "c:\temp\macro itemlist2 for rate3.txt"; data second ;infile stud2 length=lg;input @;input @1 eachline $varying700. lg; run; data both; set first second; run; data _null_;set both; file "&WD&scale..con"; /*file "c:\temp\test.txt";*/ put (eachline)(150.0); run; %macro abatch(howmany); %Do i=1 %to &howmany; %GOWINSTEP %end; %mend abatch; %abatch(&bt); proc printto log=log; run; /*start here*/ %macro readit(themeas); data all; infile "&mainfolder.&scale\Xfiles\&themeas..xf"; input semi $ 1-1 ord 19-22@; /* Note - could also use input semi $ 1 @; don't go to second line - SAS deafult - 1 line is 1 observation!*/ if semi ^= ';'; if ord^=-1; input dummy z&themeas 37-43 r&themeas 44-50; dummy=1; sqz=(z&themeas*z&themeas); run; proc sort; by dummy;run; proc means noprint; var sqz; by dummy; output out=&themeas mean=bootgenerror; run; data &themeas.z; set &themeas; length name $10; name="&themeas"; run; %mend readit; %macro writebootgen(a); %macro readitmany(howmany); %Do i=1 %to &howmany; %readit(&a.b&i); run; %end; %mend; %readitmany(&bt); data herex.&a; set %do j=1 %to &bt; &a.b&j.z %end; ; proc sort; by bootgenerror; %mend writebootgen; /* change old - before automation*/ %include "c:\temp\macro write for &scale..txt"; %macro readbootgen(theboot); data all;set herex.&theboot; proc sort; by dummy; proc means data=all noprint mean min max p95 p5 stderr STD; var bootgenerror; by dummy; output out=&theboot mean=catgenerror min=catgenerrormin max=catgenerrormax p5=catgenerrorp5 p95=catgenerrorp95 stderr=ER STD=SD; data &theboot.z; set &theboot; length name $10; /* new line I just put in */ name="&theboot"; run; ods trace on; proc univariate data=all; var bootgenerror; by dummy; output out=&theboot.z2 pctlpts=2.5 97.5 pctlpre=p_; run; data &theboot.z; merge &theboot.z &theboot.z2; run; %mend readbootgen; %include "c:\temp\macro read for &scale..txt"; data result1&scale /*&scale._OptCat2b&bt*/; set %include "c:\temp\macro rc for &scale..txt"; ; CURRENTDATE=date(); Analyst="&SYSUSERID"; run; proc sort; by catgenerror; run; /*these are actual data sets*/ data result2&scale; set herex.RC1 herex.RC2 herex.RC3; CURRENTDATE=date(); Analyst="&SYSUSERID"; RECODING=substr(name,1,3); run; proc sort; by RECODING;run; proc rank data=result2&scale groups=100 out=result2&scale; by RECODING; var bootgenerror; ranks RANK_within_RECODING; run; /*converting them into excel files*/ PROC EXPORT DATA= result1&scale OUTFILE= "&mainfolder.RESULT1.&scale..xls" DBMS=EXCEL2000 REPLACE; RUN; PROC EXPORT DATA= result2&scale OUTFILE= "&mainfolder.RESULT2.&scale..xls" DBMS=EXCEL2000 REPLACE; RUN; %let name_of_doc=&mainfolder.RESULT3.&scale.PLOT.txt; option NOCENTER; PROC PRINTTO PRINT="&name_of_doc" new; RUN; options formdlim=' '; proc univariate data=result2&scale plot; by ECODING; var bootgenerror; run; PROC PRINTTO PRINT=PRINT; run; quit; /*x "notepad &name_of_doc";/