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

Hi All -

 

DATA AREABAR;
SET cpudata2;
RETAIN x 0 y 0 id 0 ;
id=id+1;
y=lpctby;
x=hour;
output;
run;
options sysprintfont="Courier" nobyline;

ods graphics on / width=10in height=7in;
%VMXGODSO(ODSTYPE=PDF,
ODSFILE='TS45.F02.PDFLIB(POLYGON)',
ODSORIENT=LANDSCAPE);
/*--Simple Area Bar Chart with Rotated Labels--*/
proc sgplot data=areabar noborder;
by smf70stn;
title 'BIT Peak CPU Usage by Hour';
polygon id=id x=x y=y / fill outline label=CUSTLAB2
fillattrs=(color=green)
labelpos=ymax rotatelabel=vertical
LABELATTRS=(Color=red Family=Arial Size=8
Style=Italic Weight=Bold);
yaxis offsetmin=.02 label='LPAR*Logical*Percent*Busy'
values= (0 to 100 by 10);
xaxis offsetmin=.02 label='Hour of Day' values= (0 to 23 by 1);

run;

%VMXGODSC;

 

I'm getting the labels vertically, but no bars.  Using code found at https://blogs.sas.com/content/graphicallyspeaking/files/2013/12/Polygon.txt.  What am I doing wrong? Output attached.

Running SAS 9.4 (TS1M3).

 

Thanks for any help given.

 

Mark

1 ACCEPTED SOLUTION

Accepted Solutions
MarkHiltbruner
Fluorite | Level 6

ballardw -

 

You nailed it! Thanks for helping me better understand the AREABAR logic.  Updated code shown below.

 

DATA AREABAR;
SET cpudata2;
RETAIN x 0 id 0 ;
id=id+1; y=0; output;
y=lpctby; output;
x=hour; output;
y=0; output;
run; 

 

Best regards,

 

Mark

View solution in original post

4 REPLIES 4
ballardw
Super User

Minor thing: Don't add punctuation at the end of a URL. The period at the end makes it a "file not found".

 

Second. What do those two macros do?

 

Since your SGPLOT has: by smf70stn; in the code but your Data Areabar doesn't one suspects a dependency based on the by variable. But without example data it is hard to test it.

 

You might provide some example data from your CPUDATA2 data set.

 

Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.

 

MarkHiltbruner
Fluorite | Level 6

ballardw -

 

Removed macro statements and replaced them with vanilla ODS statements. Seew complete code below and please find attached CPUDATA2 output from PROC PRINT.print. Taking out the BY SMF70STN causes SGPLOT to print all observations in the file, which I don't want.  Yes, I know there are other ways to handle this, but I can fix later. 

 

data cpubusy/view=cpubusy;
set pdb.asumcelp;
month=month(datepart(startime));
hour=hour(timepart(startime));
if lparname='PHYSICAL' then smf70stn='OVERHEAD';
if SMF70STN=' ' then delete;
proc sort data=cpubusy out=cpusorted;
by smf70stn month hour descending lpctby;
data cpureport (keep=smf70stn month hour startime lpctby);
set cpusorted;
by smf70stn month hour;
if first.hour;
run;
data cpudata;
SET cpureport;

RETAIN SAVMONTH;
IF _N_ = 1 THEN
SAVMONTH = MONTH;
ELSE
IF MONTH = SAVMONTH THEN
SAVMONTH = MONTH;
ELSE
DELETE;
RUN;
DATA CPUDATA2;
SET CPUDATA;
LENGTH CUSTLAB1 $ 6;
LENGTH CUSTLAB2 $ 11;
RETAIN DAY YEAR DATE DAYLIT MONTHLIT CUSTLAB1 CUSTLAB2;
DAY=DAY(DATEPART(STARTIME));
YEAR=YEAR(DATEPART(STARTIME));

DATE=DATEPART(STARTIME);
DAYLIT=PUT(DATE,DOWNAME3.);
MONTHLIT=PUT(DATE,MONNAME3.);
CUSTLAB1=CATX('',MONTHLIT,DAY);
CUSTLAB2=CATX(', ',DAYLIT,CUSTLAB1);
OUTPUT;
RUN;
DATA AREABAR;
SET cpudata2;
RETAIN x 0 y 0 id 0 ;
id=id+1;
y=lpctby;
x=hour;
output;
run;
options sysprintfont="Courier" nobyline orientation='landscape';

ods listing close;
ods graphics on / width=10in height=7in;
ods pdf file='TS45.F02.PDFLIB(POLYGON)';
/*--Simple Area Bar Chart with Rotated Labels--*/
proc sgplot data=areabar noborder;
title 'BIT Peak CPU Usage by Hour';
polygon id=id x=x y=y / fill outline label=CUSTLAB2
fillattrs=(color=green)
labelpos=ymax rotatelabel=vertical
LABELATTRS=(Color=red Family=Arial Size=8
Style=Italic Weight=Bold);
yaxis offsetmin=.02 label='LPAR*Logical*Percent*Busy'
values= (0 to 100 by 10);
xaxis offsetmin=.02 label='Hour of Day' values= (0 to 23 by 1);
run;

ballardw
Super User

1) Can't test code against pictures of data.

 

If you go back to the referenced code an look at the created example AreaBar data set you will see that ID is repeated exactly 4 times for each Id. That is because the Id identifies a unique polygon, in this case Rectangles, which have 4 vertices. Your data has exactly 1 observation per ID value. So you have exactly one vertex per polygon (x1,y1). You need to create all four corners of the rectangle:

(x,y1) (x1,y2) (x2,y2) (x2,y1)

The order is important, either a clockwise or counterclockwise order. you won't like what happens with (x1,y1) (x2,y2)(x1,y2)(x2,y1) or similar.

For example in the referenced website the x,y values for the first id are:

 

 

Obs x y id
1 $0 $0 1
2 $0 $13,164 1
3 $36,347 $13,164 1
4 $36,347 $0 1
MarkHiltbruner
Fluorite | Level 6

ballardw -

 

You nailed it! Thanks for helping me better understand the AREABAR logic.  Updated code shown below.

 

DATA AREABAR;
SET cpudata2;
RETAIN x 0 id 0 ;
id=id+1; y=0; output;
y=lpctby; output;
x=hour; output;
y=0; output;
run; 

 

Best regards,

 

Mark

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 4 replies
  • 1434 views
  • 0 likes
  • 2 in conversation