/* Creating reports with PROC REPORT */ /* Using the gardeners' data */ DATA garden; *INFILE 'z:\My Documents\teaching\stat_517\garden_multline_expand.txt'; FILENAME webpage URL 'http://people.stat.sc.edu/hitchcock/garden_multline_expand.txt'; INFILE webpage; INPUT gardener $ #2 tomato grape spinach / location $ soiltype $; /* EXAMPLE 1 */ PROC REPORT DATA=garden NOWINDOWS HEADSKIP; TITLE 'Report on Gardeners'; run; /* EXAMPLE 2 */ PROC REPORT DATA=garden NOWINDOWS HEADLINE; COLUMN tomato grape spinach; *DEFINE tomato / DISPLAY; *produces a row for each observation; TITLE "Report on Gardeners' Yields"; run; /* EXAMPLE 3 */ PROC REPORT DATA=garden NOWINDOWS HEADLINE MISSING; COLUMN location soiltype tomato grape spinach; DEFINE location / ORDER 'Garden / Location'; BREAK AFTER location / SUMMARIZE OL SKIP; * Provides summary breaks after each value of "location"; RBREAK AFTER / SUMMARIZE OL SKIP; * Provides overall summary break after report; TITLE 'Detailed Report on Gardeners'; run; /* EXAMPLE 4 */ PROC REPORT DATA=garden NOWINDOWS HEADLINE MISSING; COLUMN soiltype tomato grape spinach; DEFINE soiltype / GROUP 'Type of / Soil'; TITLE 'Report on Gardeners, Separated by Soil Type'; run; /* EXAMPLE 5 */ PROC REPORT DATA=garden NOWINDOWS HEADLINE; COLUMN location soiltype tomato grape spinach; DEFINE soiltype / GROUP 'Type of / Soil'; DEFINE location / GROUP 'Garden / Location'; TITLE 'Report on Gardeners, Grouped by Soil Type and Location'; run; /* EXAMPLE 6 */ PROC REPORT DATA=garden NOWINDOWS HEADLINE; COLUMN soiltype location, (tomato grape spinach); *Sums produced for the variables in parentheses; DEFINE soiltype / GROUP 'Type of / Soil'; DEFINE location / ACROSS 'Garden / Location'; TITLE 'Report on Gardeners, Rows are Soil Types, Columns are Locations'; run; /* EXAMPLE 7 */ /* Printing summary statistics in reports */ PROC REPORT DATA=garden NOWINDOWS HEADLINE; COLUMN soiltype (tomato grape spinach), (MEAN STD) N; DEFINE soiltype / GROUP 'Type of / Soil'; TITLE 'Summary Statistics for Different Crops, Separated by Soil Type'; run; /* EXAMPLE 8 */ /* COMPUTE new variables (both numeric and character) */ PROC REPORT DATA=garden NOWINDOWS; COLUMN location soiltype tomato grape spinach veggies hardness profit; * note the extra three variable names in the COLUMN statement; DEFINE tomato / ANALYSIS SUM NOPRINT; DEFINE spinach / ANALYSIS SUM NOPRINT; DEFINE grape / ANALYSIS SUM NOPRINT; DEFINE soiltype / NOPRINT; DEFINE veggies / COMPUTED 'Total/Vegetables'; DEFINE hardness/ COMPUTED 'Soil/Hardness'; DEFINE profit / COMPUTED; COMPUTE veggies; veggies = tomato.SUM + spinach.SUM; ENDCOMP; COMPUTE hardness / CHAR LENGTH = 4; IF soiltype='clay' THEN hardness = 'Hard'; ELSE hardness = 'Soft'; ENDCOMP; COMPUTE profit; IF location='home' THEN profit = 20*tomato.SUM + 30*grape.SUM + 15*spinach.SUM - 500; ELSE profit = 20*tomato.SUM + 30*grape.SUM + 15*spinach.SUM - 100; ENDCOMP; TITLE 'Report with Computed Variables'; run;