%let gpath='C:\';
%let dpi=200;
ods html close;
ods listing gpath=&gpath image_dpi=&dpi;
data Questions;
input Qid Question $4-64;
datalines;
1 I read only if I have to.
2 Reading is one of my favorite hobbies.
3 I find it hard to finish books.
4 I feel happy when I receive a book as a present.
5 For me, reading is a waste of time.
;
run;
/*--Create Survey data set with 5 questions with 4 response options--*/
data Likert_4;
keep Qid Question Country Group Value SumAgree SumDisagree Low High Low2 HIgh2;
format Value SumAgree SumDisagree percent6.0;
length Group $20 Country $6;
set Questions;
do Country='USA', 'Mexico', 'Canada';
a=ranuni(2); total=a;
b=ranuni(2); total=total+b;
c=ranuni(2); total=total+c;
d=ranuni(2); total=total+d;
SumDisagree=(a+b)/total;
delta=sumdisagree;
Group='Strongly Disagree'; value=a/total; Low=0; High=Low+value;
Low2=low-delta; High2=High-delta; output;
SumDisagree=.;
Group='Disagree'; value=b/total; Low=High; High=Low+value;
Low2=low-delta; High2=High-delta; output;
Group='Agree'; value=c/total; Low=High; High=Low+value;
Low2=low-delta; High2=High-delta; output;
SumAgree=(c+d)/total;
Group='Strongly Agree'; value=d/total; Low=High; High=Low+value;
Low2=low-delta; High2=High-delta; output;
SumAgree=.;
end;
run;
/*ods html;*/
/*proc print data=Likert_4(obs=6);*/
/*var Qid Country Group Value;*/
/*run;*/
/*ods html close;*/
%let red=cxcf3f3f;
%let green=cx2fbf2f;
/*--Create a style with custom colors using MODSTYLE--*/
%modstyle(name=likert, parent=listing, type=CLM,
fillcolors=cxcf3f3f pink lightgreen cx2fbf2f, colors=black black black black)
/*--Likert Panel--*/
ods listing style=styles.likert;
ods graphics / reset width=5in height=4in imagename='Likert_Panel_4';
title 'Survey Responses to Questions by Country';
proc sgpanel data=Likert_4 ;
/* styleattrs datacolors=(&red pink lightgreen &green) datacontrastcolors=(black);*/
panelby question / layout=panel columns=1 onepanel novarname noborder nowall;
highlow y=country low=low high=high / group=group type=bar nooutline
lowlabel=sumdisagree highlabel=sumagree;
rowaxis display=(nolabel noticks) fitpolicy=none;
colaxis display=(nolabel noticks novalues);
keylegend / noborder;
run;
/*--Create style to suppress border and axis lines--*/
proc template;
define style styles.noborder;
parent = styles.likert;
class GraphBorderLines / lineThickness=0px;
class GraphAxisLines / linethickness = 0px;
end;
run;
/*--Likert Panel with Inset No Border--*/
ods listing style=styles.noborder;
ods graphics / reset width=5in height=4in imagename='Likert_4_Inset';
title 'Survey Responses to Questions by Country';
proc sgpanel data=Likert_4 ;
/* styleattrs datacolors=(&red pink lightgreen &green) datacontrastcolors=(black);*/
panelby question / layout=panel columns=1 onepanel novarname noborder noheader nowall;
highlow y=country low=low high=high / group=group type=bar nooutline
lowlabel=sumdisagree highlabel=sumagree dataskin=pressed;
inset question / position=top nolabel textattrs=(size=10);
rowaxis display=(nolabel noticks noline) offsetmax=0.35 fitpolicy=none;
colaxis display=(nolabel noticks novalues noline);
keylegend / noborder;
run;
/*--SAS 9.4 - Likert Panel with Inset No Border--*/
ods listing style=styles.noborder;
ods graphics / reset width=5in height=4in imagename='Likert_4_SegLabel';
title 'Survey Responses to Questions by Country';
proc sgpanel data=Likert_4 ;
panelby question / layout=panel columns=1 onepanel novarname noborder noheader nowall;
hbarparm category=country response=value / group=group nooutline groupdisplay=stack
seglabel dataskin=pressed seglabelfitpolicy=none seglabelattrs=(size=6 weight=bold);
inset question / position=top nolabel textattrs=(size=8);
rowaxis display=(nolabel noticks noline) offsetmax=0.35 fitpolicy=none reverse;
colaxis display=(nolabel noticks novalues noline);
keylegend / noborder;
run;
/*--Likert Panel Centered with Inset No Border--*/
ods listing style=styles.noborder;
ods graphics / reset width=5in height=4in imagename='Likert_Center_4';
title 'Survey Responses to Questions by Country';
proc sgpanel data=Likert_4 ;
panelby question / layout=panel columns=1 onepanel novarname noborder noheader nowall;
highlow y=country low=low2 high=high2 / group=group type=bar nooutline
lowlabel=sumdisagree highlabel=sumagree dataskin=pressed;
inset question / position=top nolabel textattrs=(size=10);
rowaxis display=(nolabel noticks noline) offsetmax=0.35 fitpolicy=none;
colaxis display=(nolabel noticks novalues noline) min=-1 max=1;
keylegend / noborder;
run;
/*--Likert Panel Centered with Inset No Border--*/
ods listing style=styles.noborder;
ods graphics / reset width=5in height=4in imagename='Likert_Center_Back_4';
title 'Survey Responses to Questions by Country';
proc sgpanel data=Likert_4 ;
panelby question / layout=panel columns=1 onepanel novarname noborder noheader nowall;
highlow y=country low=low2 high=high2 / group=group type=bar nooutline
lowlabel=sumdisagree highlabel=sumagree dataskin=pressed;
inset question / position=top nolabel textattrs=(size=8) opaque backcolor=lightgray;
rowaxis display=(nolabel noticks noline) offsetmax=0.4 fitpolicy=none;
colaxis display=(nolabel noticks novalues noline) min=-1 max=1;
keylegend / noborder;
run;
/*--Create Survey data set with 5 questions with 5 response options--*/
data Likert_5;
keep Qid Question Country Group Value SumAgree SumDisagree Low High Low2 HIgh2;
format Value SumAgree SumDisagree Low2 High2 percent6.0;
length Group $20 Country $6;
set Questions;
do Country='USA', 'Mexico', 'Canada';
a=ranuni(2); total=a;
b=ranuni(2); total=total+b;
c=ranuni(2); total=total+c;
d=ranuni(2); total=total+d;
e=ranuni(2); total=total+e;
SumDisagree=(a+ b)/total;
delta=(a+ b + c/2)/total;
Group='Strongly Disagree'; value=a/total; Low=0; High=Low+value;
Low2=low-delta; High2=High-delta; output;
SumDisagree=.;
Group='Disagree'; value=b/total; Low=High; High=Low+value;
Low2=low-delta; High2=High-delta; output;
Group='Neutral'; value=c/total; Low=High; High=Low+value;
Low2=low-delta; High2=High-delta; output;
Group='Agree'; value=d/total; Low=High; High=Low+value;
Low2=low-delta; High2=High-delta; output;
SumAgree=(d +e)/total;
Group='Strongly Agree'; value=e/total; Low=High; High=Low+value;
Low2=low-delta; High2=High-delta; output;
SumAgree=.;
end;
run;
/*--Likert 5 Panel with Inset No Border--*/
ods listing style=styles.noborder;
ods graphics / reset width=5in height=4in imagename='Likert_5_Inset';
title 'Survey Responses to Questions by Country';
proc sgpanel data=Likert_5 ;
styleattrs datacolors=(&red pink white lightgreen &green) datacontrastcolors=(black);
panelby question / layout=panel columns=1 onepanel novarname noborder noheader nowall;
highlow y=country low=low high=high / group=group type=bar nooutline
lowlabel=sumdisagree highlabel=sumagree dataskin=pressed;
inset question / position=top nolabel textattrs=(size=10);
rowaxis display=(nolabel noticks noline) offsetmax=0.35 fitpolicy=none;
colaxis display=(nolabel noticks novalues noline);
keylegend / noborder;
run;
/*--Likert 5 Panel Centered with Inset No Border--*/
ods listing style=styles.noborder;
ods graphics / reset width=5in height=4in imagename='Likert_Center_5';
title 'Survey Responses to Questions by Country';
proc sgpanel data=Likert_5 ;
styleattrs datacolors=(&red pink lightyellow lightgreen &green) datacontrastcolors=(black);
panelby question / layout=panel columns=1 onepanel novarname noborder noheader nowall;
/* refline 0 / axis=x;*/
highlow y=country low=low2 high=high2 / group=group type=bar nooutline
lowlabel=sumdisagree highlabel=sumagree dataskin=pressed;
inset question / position=topleft nolabel textattrs=(size=10);
rowaxis display=(nolabel noticks noline) offsetmax=0.35 fitpolicy=none;
colaxis display=(nolabel noline) min=-1 max=1;
keylegend / noborder;
run;
/*--Likert 5 Panel Centered with Inset No Border--*/
ods listing style=styles.noborder;
ods graphics / reset width=5in height=4in imagename='Likert_Center_Back_5';
title 'Survey Responses to Questions by Country';
proc sgpanel data=Likert_5 ;
styleattrs datacolors=(&red pink lightyellow lightgreen &green) datacontrastcolors=(black);
panelby question / layout=panel columns=1 onepanel novarname noborder noheader nowall;
highlow y=country low=low2 high=high2 / group=group type=bar nooutline
lowlabel=sumdisagree highlabel=sumagree dataskin=pressed;
inset question / position=topleft nolabel textattrs=(size=8) opaque backcolor=lightgray;;
rowaxis display=(nolabel noticks noline) offsetmax=0.4 fitpolicy=none;
colaxis display=(nolabel noline) min=-1 max=1;
keylegend / noborder;
run;
/*--Likert Icon--*/
ods listing style=styles.noborder image_dpi=100;
ods graphics / reset width=2.7in height=1.8in imagename='Likert_Icon';
title 'Survey Responses to Questions by Country';
proc sgpanel data=Likert_4(where=(Qid < 3)) ;
panelby question / layout=panel columns=1 onepanel novarname noborder noheader nowall;
highlow y=country low=low high=high / group=group type=bar nooutline
lowlabel=sumdisagree highlabel=sumagree dataskin=pressed;
inset question / position=top nolabel textattrs=(size=10);
rowaxis display=(nolabel noticks noline) offsetmax=0.35 fitpolicy=none;
colaxis display=(nolabel noticks novalues noline);
keylegend / noborder;
run;