BookmarkSubscribeRSS Feed
ballardw
Super User

gsThe code below will generate a PDF document with a PROC PRINT table and two sgraphics plots for all of the styles currently active in your SAS system. I believe it should work on SAS 9 and higher. Change the output path macro variable to send the output to your desired folder.

I find it helpful in choosing which style to use or modify and especially for graphics colors, outline colors (look real close at some of the barcharts), line and marker types and colors. Hopefully this may help some folks delving into graphics and wondering which color is associated with which data value or element.

The basis of this code was found in a paper or example but the source didn't survive the last time my IT department upgraded my computer. So if it was your code I'm sorry I can't give you credit.

A section at the bottom will also create a text document of the description of the styles if wanted.

 

/* This program will create output that allows you to see the

appearance of all of the SAS output styles currently

available to you in PDF output.

A table generate by a basic PROC print, a barchart and line chart

are generated to see a majority of basic defaults in appearance.

*/

/* folder to direct all of the output files to*/

%let OutPath= D:\Data\examples\styletest\junk2;

/* Create a dataset with the style names*/

/*ODS output stats(MATCH_ALL=mvar)=Temp1; prior to v9.0 replaced*/

ODS output stats=work.Temp1;

proc template; list styles;run;

ods output close;

data work.TemplateListing;

length type $12 path $155;

set work.temp1;

if type="Style";

run;

/* create macro vriables from the style names */

data _null_;

set work.TemplateListing end=eof;

retain Counter 1;

if eof then call symput("NumStyles",Counter);

StyleName=Path;

StyleNum=trim(left(compress("Style"||Counter)));

call symput (StyleNum, trim(left(StyleName)));

Counter+1;

run;

/* make a small dataset to display with the style */

Data test;

input A B C e f g h i j k l m n o p q r s t u v w x y z;

cards;

1 2 3 2 5 74 1 6 8 9 75 2 1 4 7 89.5 62 1 1 4 5 5 656.3 25 54 5 5 5 5 1 0 54 74 7 85 8 5 41 23 8 93 12 86 3

4 5 6 75 2 1 4 7 89 62 1 75 2 1 4 7 89 62 1 75 2 1 4 7 89 62 1 75 2 1 4 7 89 62 1 2 5 74 1 6 8 9 75 2 1

7 8 9 2 5 74 1 6 8 9 75 2 1 2 5 74 1.1 6 8 9 75 2 1 2 5 74 1 6 8 9 75 2 1 2 5 74 1 6 8 9 75 2 1

;

run;

/* and another to graph as vertical bar chart*/

data Barchart;

input where $ when group;

value = 10*ranuni(345) + 1;

value = round(value,.01);

datalines;

Region 1990 1

Region 1991 2

Region 1992 3

Region 1993 4

Region 1994 5

Region 1995 6

Region 1996 7

Region 1997 8

Region 1998 9

Region 1999 10

Region 2000 11

Region 2001 12

Region 2002 13

Region 2003 14

State 1990 1

State 1991 2

State 1992 3

State 1993 4

State 1994 5

State 1995 6

State 1996 7

State 1997 8

State 1998 9

State 1999 10

State 2000 11

State 2001 12

State 2002 13

State 2003 14

;

run;

/* graph as line plot*/

Data linechart;

do series = 1 to 14;

do Year= 2000 to 2005;

Value=series;

output;

end;

end;

run;

%macro DisplayStylesPDF;

ODS LISTING CLOSE;

ODS PDF File="&OutPath\styletest.PDF" ;

ods pdf pdftoc=1 ;

ods noproctitle;

%do C= 1 %to 4;

/* %do C=1 %to &NumStyles;*/

ODS PDF style=&&Style&C;

ods pdf startpage=yes;

title "Main Title for &&Style&C";

Title2 "Secondary Title for &&Style&C";

/* ODS PROCLABEL "";*/

ODS PROCLABEL "Table using &&Style&C";

proc print data=test

/* contents="Example data using&&Style&C" */

;

run;

ods pdf startpage=no;

ods graphics / noscale height=5in width=7.5in;

ODS PROCLABEL "Barchart using &&Style&C";

/* try removing description as it appears to leave blank link in TOC

without description it basically does the PROC title description=""

*/

proc sgpanel data=Barchart ;

title "Barchart chart example using &&Style&C";

panelby where /columns=1 rows=2 novarname ;

vbar when /response=value group=group stat=sum;

format value best4.;

rowaxis label='Values';

colaxis fitpolicy=rotate display=(nolabel);

run;

ODS PROCLABEL "Line Chart using &&Style&C label";

proc sgplot data=linechart description="";

title "Line chart example using &&Style&C title";

yaxis values=(1 to 14 by 1);

series x=Year y=Value /group=series markers;

label series="Graph default line, color and marker for style: &&Style&C";

run;

title;

%end;

ODS PDF CLOSE;

%Mend DisplayStylesPDF;

/*options mprint;*/

%DisplayStylesPDF;

/*options nomprint;*/

title;

/*remove comment below to see PDF output*/

*%DisplayStylesPDf;

/* write out the source/description of the styles if you want to see them */

%macro StyleSource;

Title "Style source";

Proc printto log="&OutPath\stylesource.txt" ;run;

%do C=1 %to &NumStyles;

Title2 "This Style is &&Style&C";

ODS PROCLABEL "This Style is &&Style&C";

proc template;

/* path sashelp.tmplmst;*/

source &&Style&C;

run;

%end;

Proc printto ;run;

%mend StyleSource;

/* remove comment below to create the source text */

/* that describes the styles. */

%StyleSource;

1 REPLY 1
Rick_SAS
SAS Super FREQ

To read a discussion that describes ODS styles, which includes graphics that display markers, line styles, and colors for several major styles, see the SAS/STAT documentation chapter "Statistical Graphics Using ODS," especially the section "Styles." Here is a direct link: http://support.sas.com/documentation/cdl/en/statug/65328/HTML/default/viewer.htm#statug_odsgraph_sec...

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
  • 1 reply
  • 827 views
  • 0 likes
  • 2 in conversation