Pyrite | Level 9

## How to BLOCK Correctly in SGPLOT SERIES?

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.

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.

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
SAS Super FREQ

## Re: How to BLOCK Correctly in SGPLOT SERIES?

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;
``````
2 REPLIES 2
Tourmaline | Level 20

## Re: How to BLOCK Correctly in SGPLOT SERIES?

You could make your variable a string:

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

SAS Super FREQ

## Re: How to BLOCK Correctly in SGPLOT SERIES?

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;
``````
Discussion stats
• 2 replies
• 639 views
• 0 likes
• 3 in conversation