Obsidian | Level 7

## Proc sgpanel - is it possible to replace solid line by dashed line when there is a data gap?

Dear Community,

I am working on a panel graph using proc sgpanel. My x-axis variables is "Years".

The series line I use is currently a solid line drawn using the code: (lineattrs=(pattern=solid thickness=2).

However, when there is a data gap where data for two or more years is missing, I would like to have a dashed line.

In other words, in each panel cell, I would like there to be a solid line but when there are missing data for more than two years, I would like the part of the line that goes from the last data point to the next data point to be dashed.

I hope this is understandable, if not, I will try to explain further.

Is it possible to do this in a sgpanel graph? In this case, how can it be done?

Best regards,

Karoline

5 REPLIES 5
SAS Super FREQ

## Re: Proc sgpanel - is it possible to replace solid line by dashed line when there is a data gap?

Well, this is a bit of a hack, but it will solve your problem.

What you should do is overlay TWO lines that are exactly the same. The first one (the bottom layer) is dashed. The second one (the top layer) is solid and uses the BREAK option to plot a gap when there are missing values.

``````data Have;
do Group = 1, 2;
do x = 0 to 6.2 by 0.25;
cnt + 1;
y = sin(Group*x);
if cnt=10 | cnt=11 | cnt=20 | cnt=21 |
cnt=30 | cnt=40 | cnt=41 then
y = .;
output;
end;
end;
run;

proc sgpanel data=Have;
panelby Group;
series x=x y=y / lineattrs=GraphData1(pattern=dash);
series x=x y=y / lineattrs=GraphData1(pattern=solid thickness=2) BREAK;
run;
``````
Obsidian | Level 7

## Re: Proc sgpanel - is it possible to replace solid line by dashed line when there is a data gap?

Thank you very much, Rick! Do you know if there is a way to only get a break when there are two consecutive missing values (years)?

I am guessing that might not be so easy.

Kind regards,

Karoline

SAS Super FREQ

## Re: Proc sgpanel - is it possible to replace solid line by dashed line when there is a data gap?

Not an easy way, no. To do that you would need to scan the data yourself and identify the observations that have two consecutive missing values. You would then have to figure out how to display that information on a graph. The obvious options are to use either annotation or the VECTOR statement.

Obsidian | Level 7

## Re: Proc sgpanel - is it possible to replace solid line by dashed line when there is a data gap?

Sorry for the late reply, Rick. Thank you for the help and clarification!

SAS Super FREQ

## Re: Proc sgpanel - is it possible to replace solid line by dashed line when there is a data gap?

I wrote down my thoughts in more detail in the article, "A trick to plot a time series that has missing values."

Discussion stats
• 5 replies
• 734 views
• 3 likes
• 2 in conversation