Posts

Showing posts from January, 2018

Creating a neat and reader-friendly SAS Chi-square test report

Image
This macro is for performing chi-square test. Both var and byvar should be categorical variables. The macro would automatically convert a numeric variable into a character variable. Therefore there is no warning or error if you feed the macro with a continuous variable. If the Fisher test consumes too much time, you can manually set fisher=0 to suppress the Fisher test. The default fisher parameter(If not specify) is 1. Example: data example; set SASHELP.electric; if Revenue>60 then revenue_Group="A"; else revenue_Group="B"; if Year<2000 then time_group="A"; else time_group="B"; keep Customer revenue_Group time_group ; run; proc freq data=example; tables (time_group revenue_Group)*Customer/norow nocol nopercent; run; %INCLUDE "/folders/myshortcuts/SASfolder/Tools/Macro_ChiSqOrFisher.sas" ; %ChiSqOrFisher(table=example,var=time_group revenue_Group,Byvar=Customer,fisher=1); Result: Macro: %Macro ChiSqOrFisher(table=,var=,B...

Creating a neat and reader-friendly SAS ANOVA report

Image
ANOVA test is a generalization of the t-test. This macro serves the same purpose as ttest macro and general a cleaning report. The macro supports multiple var or byvar parameters. Example: data example; set SASHELP.applianc; if MOD(cycle,2)=1 then Group="A"; else Group="B"; keep units_1-units_6 group; run; proc print data=example(obs=8); run; %INCLUDE "/folders/myshortcuts/SASfolder/Tools/MacroANOVA.sas"; %MacroANOVA(table=example,var=units_1 units_2 units_3 units_4 units_5 units_6,Byvar=Group); Result: Macro: %INCLUDE "/folders/myshortcuts/SASfolder/Tools/NumToStr.sas" ; %MACRO MacroANOVA_hidden(table=,var=,Byvar=,alpha=); proc sql noprint;         select          "if "||compress("&Byvar= '"||&Byvar||"'")|| " then "||compress("&Byvar='level"||n||"'")         into:ChangeLevel separated by ';'                 from temp1;        ...

Creating a neat and reader-friendly SAS t-test report

Image
The following SAS macro is for creating a neat and reader-friendly t-test report. The primary goal of this code is to make the t-test report easy to read for every person. The secondary goal is to reduce statisticians' workload. The macro has the ability to run multiple t-tests at a time, which can simplify SAS code greatly. If you have any problem with running this macro, please leave your comment to let me know. Example code: data example; set SASHELP.applianc; if MOD(cycle,2)=1 then Group="A"; else Group="B"; keep units_1-units_6 group; run; proc print data=example(obs=8); run; %INCLUDE "/folders/myshortcuts/SASfolder/Tools/MacroTTest.sas"; %MacroTTest(table=example,var=units_1 units_2 units_3 units_4 units_5 units_6,Byvar=Group); Result: Macro: %MACRO MacroTTest_hiden(table=,var=,Byvar=,title=0,alpha=); /*Change a given variable to character*/ %INCLUDE "/folders/myshortcuts/SASfolder/Tools/NumToStr.sas" ; %Num2Str(tabl...