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;