Proportion Testing in SAS and R
If tests of proportions are needed for various levels of summary of data, you can use SAS to create a file that can be used by R to run proportion tests. For example, if you have data summarized by race, age groups, and some other variable, and you want to test the rates or proportions for each value of the variable for each race, age group, and race-age group combination with the population estimates for a particular year, you can summarize the data and merge with SAS, then create a file with the R commands.
proportiontest.sas
—
Plain Text,
1Kb
File contents
data _NULL_;
/* Set lengths for character strings to be created */
length ACS_condition $30. object_string $40.;
/* Output file that will contain the R code to be executed */
file "By-Ethnicity-Proportions-2001.R";
set patient.admissions end=eof;
/* This statement tells R to sent the output to a file, rather than
display the results on the terminal */
if _N_ eq 1 then put "sink(""2001-Proportions.txt"")";
/* This put the formated value of the variable into a character string
e.g. 11 becomes "Asthma", 18 becomes "Diabetes", etc. */
ACS_condition = put(ACS_group,ACS_ALL.);
/* This statement creates an R object for the population estimates */
put "population.estimate.2001 <- c(" White_est "," Black_est ",
" Hispanic_est ")";
/* This statement creates an R object for the count of admissions */
put ACS_condition "<- c(" White_Admissions "," Black_Admissions ",
" Hispanic_Admissions ")";
/* The name of the condition is concatenated with the word "result" */
object_string = trim(left(ACS_condition)) || ".result";
/* The code to be executed - */
put object_string "<- prop.test(" ACS_condition ", population.estimate.2001)";
/* This prints the R output into the file specified at the beginning */
put "print(" object_string ")";
/* This closes the R output file after all the tests are run */
if eof then put "sink()";
run;

