BookmarkSubscribeRSS Feed
KarolineN
Obsidian | Level 7

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? 

Any advice would be helpful.

 

Best regards,

Karoline

5 REPLIES 5
Rick_SAS
SAS Super FREQ

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;
KarolineN
Obsidian | Level 7

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

Rick_SAS
SAS Super FREQ

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. 

KarolineN
Obsidian | Level 7

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

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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