Help using Base SAS procedures

Creating graphs in sas

Reply
Super Contributor
Posts: 259

Creating graphs in sas

I have a list of 20-30 factors which I would like to create 4 graphs each for. Ideally I would like them in an excel file, each on a separate sheet (four graphs per sheet) but I know that's next too impossible. Exporting to powerpoint and pdf are sufficient alternatives. What I like about Excel is that you can separate each factor into its own workbook. I have started the process off using robslink.com as a reference.

My code is below (which I took from http://www.robslink.com/SAS/democd7/clin1_info.htm)

Couple of points:

  • I am trying to get one factor right so I have just created a dataset with one factor and dummy values.
  • I want 4 graphs but using the same graph here 4 times for illustrative purposes
  • In the reference above, the first few lines of code where he defines htmlvar, I'm not sure what this does.

My main challenges are:

  • In the link above he creates a bar chart with a line chart on a secondary graph and retains with a "MS excel look". I can reproduce a single graph but I need guidance on how to create 4 on a single page, that are the same size. I'm not sure what the code highlighted in red does.
  • I want the code to be flexible so that it can handle loads of different factors with different ranges of levels, some numeric (age) and some character (occupation).
  • The code highlighted in pink is not from the above link. I took it from a different source about exporting 4 graphs to a pdf. it doesn't work properly for me (graphs appear on a pdf but they don't have the format  created by robslink code and they are not fitted correctly on the page.

data my_data;
INFILE DATALINES DLM=',';
format factor level $16.;
input factor $ level $ exposure lossratio ;
datalines ;
occupation,professional,500,.44
occupation,student,1000,.55
occupation,retired,2000,.75
;
run;

data my_data; set my_data;
length htmlvar $500;
htmlvar=
'title='||quote(
  'Level: '|| trim(left(level)) ||'0D'x||
  'Vehicle Exposure Years: '|| trim(left(v01_veh_exp_years))||
  'Loss Ratio: '|| trim(left(all_LR)))||
' href="clin1_info.htm"';
run;


goptions device=png;
goptions xpixels=750 ypixels=500;
goptions noborder;

ODS LISTING CLOSE;
ODS HTML path=odsout body="&name..htm"
(title="SAS/Graph gbarline Line & Column Chart") style=sasweb;

goptions gunit=pct htitle=6 ftitle="albany amt/bold" htext=4.25 ftext="albany amt/bold";

title1 ls=1.5 "&name. - LR";
/*title2 "Classic Combination Chart";*/

pattern1 v=solid color=cx993366; 

symbol1 interpol=join width=3 value=dot height=4 color=navy; 

axis1 label=(a=90 'Exposure Years') offset=(0,2) order=(0 to 30000 by 5000) major=(h=-1) minor=none;
axis2 label=(a=90 'Loss Ratio') offset=(0,2) order=(0 to 2 by .5) major=(h=-1) minor=none;
axis3 label = none value=(angle=90) offset=(13,13) ;

device=pdfc
ftext="swissb";
ods pdf file="H:\Commercial\Fleet\Presentations\four in one.pdf" startpage=never;
ods proclabel "Four graphs on one page" ;
goptions hsize=5.20 in vsize=3.75 in;
title1;

proc gbarline data=my_data2;
goptions horigin=0in vorigin=3.99 in;
bar level / discrete
  type=sum sumvar=v01_veh_exp_years
  axis=axis1 maxis=axis3
  space=5 width=6
  html=htmlvar
  des='' name="&name" ;
plot /
  type=sum sumvar=all_LR
  axis=axis2
  html=htmlvar;
run;

quit;

proc gbarline data=my_data2;
goptions horigin=5.25;
bar level / discrete
  type=sum sumvar=v01_veh_exp_years
  axis=axis1 maxis=axis3
  space=5 width=6
  html=htmlvar
  des='' name="&name" ;
plot /
  type=sum sumvar=all_LR
  axis=axis2
  html=htmlvar;
run;

quit;


proc gbarline data=my_data2;
goptions hsize= 5.20in vsize= 3.75in device=pdfc ftext="swissb"
bar level / discrete
  type=sum sumvar=v01_veh_exp_years
  axis=axis1 maxis=axis3
  space=5 width=6
  html=htmlvar
  des='' name="&name" ;
plot /
  type=sum sumvar=all_LR
  axis=axis2
  html=htmlvar;
run;

quit;


proc gbarline data=my_data2;
goptions horigin=5.25 in;
bar level / discrete
  type=sum sumvar=v01_veh_exp_years
  axis=axis1 maxis=axis3
  space=5 width=6
  html=htmlvar
  des='' name="&name" ;
plot /
  type=sum sumvar=all_LR
  axis=axis2
  html=htmlvar;
run;

quit;

ods pdf close;

Super User
Posts: 19,822

Re: Creating graphs in sas

You need to post this under the graphics forum:

http://support.sas.com/resources/papers/proceedings12/285-2012.pdf

Ask a Question
Discussion stats
  • 1 reply
  • 198 views
  • 0 likes
  • 2 in conversation