PROC IMPORT OUT= WORK.rccc DATAFILE= "/home/grego1/STAT 540/County_Survey.xlsx" DBMS=XLSX REPLACE; sheet="RawData"; RUN; proc contents data=rccc; run; /*The data names are shortened versions of the labels. The labels are a little */ /*cryptic, but we can leave them alone. We rename variables below */ data rccc; set rccc; /* The variable names q2_1, q2_2, q2_3 cause problems later on, but reflect a */ /* difficulty encountered when importing an actual SPSSX data set. */ rename 'GENDER OF RESPONDENT'n=GENDER 'HOW FAMILIAR WITH CONSERVATION A'n=Q2_1 'HOW FAMILIAR WITH GRANTS TO PROM'n=Q2_2 'HOW FAMILIAR WITH GRANTS TO REST'n=Q2_3 'HOW FAMILIAR WITH RICHLAND COUNT'n=Q2_4 'JOB DONE PROTECTING WATER QUALIT'n=Q3 'JOB DONE PROTECTING DRINKING WAT'n=Q4 'JOB DONE PROTECTING NATURAL AREA'n=Q5 'JOB DONE PROTECTING WORKING FARM'n=Q6 'JOB DONE PROVIDING GREENWAYS'n=Q7; run; /*Playing with some of the new ODS OUTPUT features available. This plot looks OK */ /* but I don't like the label (I can't change the default) and I would prefer */ /* percentages to frequencies. We got lucky with the labels */ ods graphics; proc freq data=rccc; tables q2_1/plots=FreqPlot out=Pq2_1; run; /* FreqPlot has a limited range of options I can modify--the scale is one of */ /* them. I save the output table in case I want to fix problems with the table */ /* using a different approach. */ proc freq data=rccc; tables q2_1/plots=FreqPlot (scale=Percent) out=Pq2_1; run; /* This table looks fine, and the label is OK */ proc freq data=rccc; tables gender/plots=FreqPlot; run; /* Big problem here--the categories are in alphabetical order. We were simply */ /* lucky that the alphabetical ordering matched the ordinal scale for q2_1 */ proc freq data=rccc; tables income/plots=FreqPlot; run; /* A panel-style graph for a two-way display. This looks OK, though gender labels are not visible */ proc freq data=rccc; tables gender*q2_1/plots=FreqPlot(scale=Percent); run; /* Here is a horizontal grouping */ proc freq data=rccc; tables gender*q2_1/plots=FreqPlot(scale=Percent twoway=grouphorizontal); run; /* Let's first figure out how to fix the label on FreqPlot for q2_1--we */ /* start with the TRACE command to do so */ ods trace on; proc freq data=rccc; tables q2_1/plots=FreqPlot(scale=Percent); run; proc freq data=rccc; tables gender*q2_1/plots=FreqPlot(scale=Percent twoway=grouphorizontal); run; ods trace off; /* The graphics template is stored in Base.Freq.Graphics.OneWayPercentChart. */ /* We use PROC TEMPLATE to see the code used to create the graph and */ /* then tweak it to print, e.g Q2.1 */ proc template; source Base.Freq.Graphics.OneWayPercentChart; source Base.Freq.Graphics.HGroupPercentChart; run; /* The definition for the source code shows that the argument _VARNAME is */ /* used to create the main title (entrytitle). We could use a macro */ /* variable in a revised definition. */ * Let's create a template that we'll then edit ; * Switch the path so that our updated template is read first; *ods path sasuser.templat(update) sashelp.tmplmst(read); ods path work.templat(update) sashelp.tmplmst(read); ods path show; options symbolgen; ods html; ods graphics; %macro oneway(textQ=, Q=); %include "/home/grego1/STAT 540/myfreq.sas"; proc freq data=rccc; *Only print the plot, not the table; ods select FreqPlot; tables &Q/plots=FreqPlot(scale=Percent); run; %mend; %oneway(textQ=Q2.1, Q=Q2_1); /* Save several graphs--this is crude and should actually be incorporated into a macro */ /* Be careful about the output device you choose! */ ods pdf file="/home/grego1/STAT 540/OneWayGraphs.pdf"; %oneway(textQ=Q2.1, Q=Q2_1); %oneway(textQ=Q2.2, Q=Q2_2); %oneway(textQ=Q2.3, Q=Q2_3); %oneway(textQ=Q2.4, Q=Q2_4); %oneway(textQ=Q3, Q=Q3); %oneway(textQ=Q4, Q=Q4); %oneway(textQ=Q5, Q=Q5); %oneway(textQ=Q6, Q=Q6); %oneway(textQ=Q7, Q=Q7); ods pdf close; run; /* Now let's fix the ordering of the Income variable. This approach requires more */ /* than other approaches (e.g., ordering records to the data set then using */ /* ORDER=DATA. */ proc format; value incfmt 1="LESS THAN $10,000" 2="$10,000 - $19,999" 3="$20,000 - $29,999" 4="$30,000 - $39,999" 5="$40,000 - $49,999" 6="$50,000 - $74,999" 7="$75,000 - $100,000" 8="$100,000 OR MORE"; run; data rccc; set rccc; format nincome incfmt.; label nincome="Income"; if income="LESS THAN $10,000" then nincome=1; else if income="$10,000 - $19,999" then nincome=2; else if income="$20,000 - $29,999" then nincome=3; else if income="$30,000 - $39,999" then nincome=4; else if income="$40,000 - $49,999" then nincome=5; else if income="$50,000 - $74,999" then nincome=6; else if income="$75,000 - $100,000" then nincome=7; else nincome=8; run; ods graphics; /* It's straightforward to fix part of the template, though it would be nice to */ /* remove all the Income= statements in the headers. */ %macro twoway(textQ=, Q=); %include "/home/grego1/STAT 540/myfreq.sas"; proc freq data=rccc; tables nincome*&Q/plots=FreqPlot(scale=Percent twoway=grouphorizontal); run; %mend; %twoway(textQ=Q2.1, Q=Q2_1); /* I want to control the panels in each frame--we can fix that with npanelpos, but */ /* we would have to edit another template to proceed. */ proc freq data=rccc; tables nincome*q2_1/plots=FreqPlot(scale=Percent twoway=grouphorizontal npanelpos=3); run; *Clean up by restoring the old search path; ods path sashelp.tmplmst(read) work.templat(update); run;