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

SGPLOT Procedure BLOCK Statement shows the following image with blocks around dots—for example, the observation for Janet is located in the middle of the second red box.

images_blockposcenter.png

I use both SERIES and BLOCK as follows—as a working example, 12 observations from January to December 2020 are displayed. A dummy variable equals one only in February and zero otherwise. The outcome, unlike the plot above, draws the February block after the second dot.

SGPlot.png

As in the first, I want the block in the middle rather than on the right of the dot. In this case, how can I relocate the block? The following is the MWE code.

data i;
	do i=1 to 12;
		t=mdy(i,1,2020);
		x+rannor(1);
		y=i=2;
		output;
	end;
run;

data j;
	input id :$ value fillcolor :$ filltransparency @@;
cards;
i 0 black 1 i 1 black 0.9
;

ods results=off;
ods listing gpath="!userprofile\desktop";
ods graphics/reset;

proc sgplot data=i dattrmap=j;
	series x=t y=x;
	block x=t block=y/attrid=i nooutline novalues;
	xaxis valuesformat=yymmddn6.;
quit;

ods graphics/reset;
ods listing gpath=none;
ods results=on;
1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

Add the points that you want to use as the boundary of the block region. Then create a binary variable that indicates whether t is in the region that you want to shade. For example, the following program uses 15Jan and 15Feb as boundary values:

 

%let Left  = mdy(1,15,2020);
%let Right = mdy(2,15,2020);

data i;
	do i=1 to 12;
		t=mdy(i,1,2020);
		x+rannor(1);
		output;
	end;
run;
/* add points at boundary of block */
data Block;
t = &Left;  output;
t = &Right; output;
run;
/* merge boundary values and then sort */
data All;
merge i Block;
by t;
BlockID = (t>=&Left & t<&Right);
format t DATE9.;
run;

proc sort data=All; by t; run;

data j;
	input id :$ value fillcolor :$ filltransparency @@;
cards;
i 0 black 1 i 1 black 0.9
;

proc sgplot data=All dattrmap=j;
	series x=t y=x;
	block x=t block=blockID /attrid=i nooutline novalues;
	xaxis valuesformat=yymmddn9.;
quit;

View solution in original post

2 REPLIES 2
ChrisNZ
Tourmaline | Level 20

You could make your variable a string:

T = put(mdy(I,1,2020),yymmdd.);

 

Rick_SAS
SAS Super FREQ

Add the points that you want to use as the boundary of the block region. Then create a binary variable that indicates whether t is in the region that you want to shade. For example, the following program uses 15Jan and 15Feb as boundary values:

 

%let Left  = mdy(1,15,2020);
%let Right = mdy(2,15,2020);

data i;
	do i=1 to 12;
		t=mdy(i,1,2020);
		x+rannor(1);
		output;
	end;
run;
/* add points at boundary of block */
data Block;
t = &Left;  output;
t = &Right; output;
run;
/* merge boundary values and then sort */
data All;
merge i Block;
by t;
BlockID = (t>=&Left & t<&Right);
format t DATE9.;
run;

proc sort data=All; by t; run;

data j;
	input id :$ value fillcolor :$ filltransparency @@;
cards;
i 0 black 1 i 1 black 0.9
;

proc sgplot data=All dattrmap=j;
	series x=t y=x;
	block x=t block=blockID /attrid=i nooutline novalues;
	xaxis valuesformat=yymmddn9.;
quit;

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