/*Factor analysis Macro*/ /*By Kaz Uekawa www.estat.us */ /*Look at the statement like these towards the end of this program. You can modify this list to specify which variables to test for each run of factor anlaysis %mend john; %john (varlist=MF3505 TCJ WSPCA WSPGLT WSPIA WSPUA); %john (varlist=FCPOIL FF142B HFBI20 MF3505 TCJ WSPCA WSPGLT);*/ %let name_of_data=sashelp.citiwk; %let name_of_doc=C:\temp\example3.txt; option NOCENTER; PROC PRINTTO PRINT="&name_of_doc" new; RUN; options formdlim=' '; %macro john (varlist=); ods listing close; proc factor data=&name_of_data ROTATE=varimax Nfactors=5; var &varlist; ods output OrthRotFactPat=result VarExplain=resultV; run; ods listing; data mainresult; set resultV result; %macro asdf (these2=); sig&these2="*"; if factor&these2 =. or ( factor&these2 < .5 and factor&these2 > 0) then sig&these2 =""; if factor&these2 = . or (factor&these2 < 0 and factor&these2 > -.5) then sig&these2 =""; %mend asdf; %asdf (these2=1); %asdf (these2=2); %asdf (these2=3); %asdf (these2=4); %asdf (these2=5); %asdf (these2=6); %asdf (these2=7); %asdf (these2=8); %asdf (these2=9); array these1 factor1 factor2 factor3 factor4 factor5 factor6 factor7 factor8 factor9 ; do over these1; these1=round(these1,0.01); end; format factor1 4.2; format factor2 4.2; format factor3 4.2; format factor4 4.2; format factor5 4.2; label=substr(label,8,30); jun=_n_; if jun=1 then label="V. Explained Bef. Rotation"; if jun=2 then label="V. Explained Aft. Rotation"; if variable="" then sig1=""; if variable="" then sig2=""; if variable="" then sig3=""; if variable="" then sig4=""; if variable="" then sig5=""; run; ods listing; proc print data=mainresult round width=minimum; title1 "Results"; title2 "Factor Pattern: Statistics Shown if factor loading > .50 (Rotation Method: Varimax)"; var variable label factor1 sig1 factor2 sig2 factor3 sig3 factor4 sig4 factor5 sig5; run; ods listing close; %mend john; %john (varlist=MF3505 TCJ WSPCA WSPGLT WSPIA WSPUA); %john (varlist=FCPOIL FF142B HFBI20 MF3505 TCJ WSPCA WSPGLT); PROC PRINTTO PRINT=PRINT; run; quit; x "notepad &name_of_doc";