BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Snowy101
Calcite | Level 5

Hello,

I saw in one of the post from Cynthia talking about the new SG procedures can represent TABLE by equivalent image form. I googled this online, but I didn't find any information about this. I am wondering if there is anyone can help me?

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Jay54
Meteorite | Level 14

This may be what you are referring to:

Weather_Table_Bands.png

The purpose is to create a graph with axis aligned table columns like this:

Weather_Table_Graph.png

Here is the code using SGPLOT procedure:


%let gpath='C:\';

data weatherTable;
  input Month $ high low precip;
  highC = (high-32) / 1.8;
  lowC  = (low-32) / 1.8;
  label high= 'Fahrenheit';
  label low = 'Fahrenheit';
  label highc='Celsius';
  label lowc= 'Celsius';
  label precip= 'Precipitation (in)';
  format high low 2.0;
  format highc lowc precip 4.1;
  x1='High(F)'; x2='Low(F)'; x3='High(C)'; x4='Low(C)'; x5='Precip(in)';
  id=_n_;
  if mod(id, 2)=0 then ref=month;
  datalines;
Jan    49   30  4.46
Feb    53   32  3.53
Mar    61   40  4.46
Apr    71   48  2.98
May    78   57  4.03
Jun    84   65  4.06
Jul    88   69  4.35
Aug    86   68  4.30
Sep    80   62  4.27
Oct    70   49  3.28
Nov    61   42  3.06
Dec    52   33  3.25
;
run;

proc sort data=weatherTable out=weatherTable2;
  by descending id;
  run;

ods html style=listing;
proc print data=weatherTable(obs=10) noobs;run;
ods html close;

ods listing gpath=&gpath style=htmlblue image_dpi=200;

proc template;
   define style Styles.HtmlblueSF;                                             
      parent = styles.Htmlblue;
      style GraphFonts from GraphFonts /                                  
         'GraphDataFont' = ("<sans-serif>, <MTsans-serif>",8pt)                             
         'GraphValueFont' = ("<sans-serif>, <MTsans-serif>",8pt);  
   end;
run;

/*--Table--*/
ods listing style=Styles.HtmlblueSF;
ods graphics / reset width=4in height=2.5in imagename='Weather_Table';
title "Average Temperatures for Raleigh";
proc sgplot data=weatherTable2 noautolegend;
  scatter y=month x=x1 / markerchar=high x2axis;
  scatter y=month x=x2 / markerchar=low x2axis;
  scatter y=month x=x3 / markerchar=highc x2axis;
  scatter y=month x=x4 / markerchar=lowc x2axis;
  scatter y=month x=x5 / markerchar=precip x2axis;
  x2axis display=(noticks nolabel) offsetmin=0.1 offsetmax=0.1;
  yaxis display=(nolabel noticks) offsetmin=0.05 offsetmax=0.05;
  run;

/*--Table with bands--*/
ods listing style=Styles.HtmlblueSF;
ods graphics / reset width=4in height=2.5in imagename='Weather_Table_Bands';
title "Average Temperatures for Raleigh";
proc sgplot data=weatherTable2 noautolegend;
  refline ref / lineattrs=(thickness=20) transparency=0.8;
  scatter y=month x=x1 / markerchar=high x2axis;
  scatter y=month x=x2 / markerchar=low x2axis;
  scatter y=month x=x3 / markerchar=highc x2axis;
  scatter y=month x=x4 / markerchar=lowc x2axis;
  scatter y=month x=x5 / markerchar=precip x2axis;
  x2axis display=(noticks nolabel) offsetmin=0.1 offsetmax=0.1;
  yaxis display=(nolabel noticks) offsetmin=0.05 offsetmax=0.05;
  run;

/*--Graph with Table--*/
ods listing style=Styles.HtmlblueSF;
ods graphics / reset width=4in height=2.5in imagename='Weather_Table_Graph';
title "Average Temperatures Range for Raleigh";
proc sgplot data=weatherTable2 noautolegend;
  refline ref / lineattrs=(thickness=18) transparency=0.9;
  band y=month lower=low upper=high / transparency=0.6;
  scatter y=month x=high / markerattrs=graphdata2(symbol=circlefilled) transparency=0.4;
  scatter y=month x=low / markerattrs=graphdata1(symbol=trianglefilled) transparency=0.4;
  scatter y=month x=x2 / markerchar=low x2axis;
  scatter y=month x=x1 / markerchar=high x2axis;
  xaxis  display=(nolabel) grid offsetmin=0.1 offsetmax=0.3;
  x2axis display=(noticks nolabel) offsetmin=0.8 offsetmax=0.08;
  yaxis display=(nolabel noticks) offsetmin=0.05 offsetmax=0.05;
  run;

View solution in original post

2 REPLIES 2
Jay54
Meteorite | Level 14

This may be what you are referring to:

Weather_Table_Bands.png

The purpose is to create a graph with axis aligned table columns like this:

Weather_Table_Graph.png

Here is the code using SGPLOT procedure:


%let gpath='C:\';

data weatherTable;
  input Month $ high low precip;
  highC = (high-32) / 1.8;
  lowC  = (low-32) / 1.8;
  label high= 'Fahrenheit';
  label low = 'Fahrenheit';
  label highc='Celsius';
  label lowc= 'Celsius';
  label precip= 'Precipitation (in)';
  format high low 2.0;
  format highc lowc precip 4.1;
  x1='High(F)'; x2='Low(F)'; x3='High(C)'; x4='Low(C)'; x5='Precip(in)';
  id=_n_;
  if mod(id, 2)=0 then ref=month;
  datalines;
Jan    49   30  4.46
Feb    53   32  3.53
Mar    61   40  4.46
Apr    71   48  2.98
May    78   57  4.03
Jun    84   65  4.06
Jul    88   69  4.35
Aug    86   68  4.30
Sep    80   62  4.27
Oct    70   49  3.28
Nov    61   42  3.06
Dec    52   33  3.25
;
run;

proc sort data=weatherTable out=weatherTable2;
  by descending id;
  run;

ods html style=listing;
proc print data=weatherTable(obs=10) noobs;run;
ods html close;

ods listing gpath=&gpath style=htmlblue image_dpi=200;

proc template;
   define style Styles.HtmlblueSF;                                             
      parent = styles.Htmlblue;
      style GraphFonts from GraphFonts /                                  
         'GraphDataFont' = ("<sans-serif>, <MTsans-serif>",8pt)                             
         'GraphValueFont' = ("<sans-serif>, <MTsans-serif>",8pt);  
   end;
run;

/*--Table--*/
ods listing style=Styles.HtmlblueSF;
ods graphics / reset width=4in height=2.5in imagename='Weather_Table';
title "Average Temperatures for Raleigh";
proc sgplot data=weatherTable2 noautolegend;
  scatter y=month x=x1 / markerchar=high x2axis;
  scatter y=month x=x2 / markerchar=low x2axis;
  scatter y=month x=x3 / markerchar=highc x2axis;
  scatter y=month x=x4 / markerchar=lowc x2axis;
  scatter y=month x=x5 / markerchar=precip x2axis;
  x2axis display=(noticks nolabel) offsetmin=0.1 offsetmax=0.1;
  yaxis display=(nolabel noticks) offsetmin=0.05 offsetmax=0.05;
  run;

/*--Table with bands--*/
ods listing style=Styles.HtmlblueSF;
ods graphics / reset width=4in height=2.5in imagename='Weather_Table_Bands';
title "Average Temperatures for Raleigh";
proc sgplot data=weatherTable2 noautolegend;
  refline ref / lineattrs=(thickness=20) transparency=0.8;
  scatter y=month x=x1 / markerchar=high x2axis;
  scatter y=month x=x2 / markerchar=low x2axis;
  scatter y=month x=x3 / markerchar=highc x2axis;
  scatter y=month x=x4 / markerchar=lowc x2axis;
  scatter y=month x=x5 / markerchar=precip x2axis;
  x2axis display=(noticks nolabel) offsetmin=0.1 offsetmax=0.1;
  yaxis display=(nolabel noticks) offsetmin=0.05 offsetmax=0.05;
  run;

/*--Graph with Table--*/
ods listing style=Styles.HtmlblueSF;
ods graphics / reset width=4in height=2.5in imagename='Weather_Table_Graph';
title "Average Temperatures Range for Raleigh";
proc sgplot data=weatherTable2 noautolegend;
  refline ref / lineattrs=(thickness=18) transparency=0.9;
  band y=month lower=low upper=high / transparency=0.6;
  scatter y=month x=high / markerattrs=graphdata2(symbol=circlefilled) transparency=0.4;
  scatter y=month x=low / markerattrs=graphdata1(symbol=trianglefilled) transparency=0.4;
  scatter y=month x=x2 / markerchar=low x2axis;
  scatter y=month x=x1 / markerchar=high x2axis;
  xaxis  display=(nolabel) grid offsetmin=0.1 offsetmax=0.3;
  x2axis display=(noticks nolabel) offsetmin=0.8 offsetmax=0.08;
  yaxis display=(nolabel noticks) offsetmin=0.05 offsetmax=0.05;
  run;

Snowy101
Calcite | Level 5

Hi Sanjay,

I am sorry for this very late reply. This is exactly what I am looking for, thank you for your efforts!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 939 views
  • 1 like
  • 2 in conversation