BookmarkSubscribeRSS Feed
Fluorite | Level 6

Hi Everyone,


I have some data I'm trying to plot but I'm at a crossroads as to how to. Here is a sample of it:

data sample;
input ID time mean test_q1 test_q2 test_q3 group_q1 $ group_q2 $ group_q3 $;
1 1 5.44 0 0 1 A A A
1 2 3.59 0 0 1 A A A
1 3 2.33 0 0 1 A A A
2 1 1.45 1 1 1 A A A
2 2 5.66 1 1 1 A A A
2 3 7.65 1 1 1 A A A
3 1 2.34 2 1 1 A A A
3 2 4.54 2 1 1 A A A
3 3 3.76 2 1 1 A A A
4 1 8.76 3 2 2 B B B
4 2 9.45 3 2 2 B B B
4 3 2.34 3 2 2 B B B
5 1 5.55 4 4 4 B B B 
5 2 2.89 4 4 4 B B B 
5 3 7.44 4 4 4 B B B

As you can see, it is repeated measures data. I am trying to do proc sgplot where x = time and y = mean, and generate a graph for each question based on the grouping variable for each question. Since it is repeated measures I need to specify it is by each ID, but I also want to group using the grouping variables. I'm not sure how to do about this as I don't think proc sgplot allows multiple grouping variables. 


Any idea on how to go about this? Any help is appreciated, thanks! 

Super User

One strongly suspects your description is incomplete. You can use as many groups as you want. The behavior may not be what you expect. By default your legend will likely be incomplete.


proc sgplot data=sample;
   scatter x=time y=mean / group= group_q1 name='q1';
   scatter x=time y=mean / group= group_q2 name='q2';
   scatter x=time y=mean / group= group_q3 name='q3';
   keylegend 'q1' 'q2' 'q3';

To incorporate TWO values, which is what I think you mean by ID and Group, then you must create one variable that will show both.

Or maybe us Proc Sgpanel with the Group_q variable(s) as PanelBy variables.

I am not sure what you expect this graph to look like. If you can draw one then we may be able to help.


I don't understand how your Test_Q variables fit in at all.


If your goal is to combine the joint levels of two (or more) categorical variables, then consider using the CATX function as shown in the section "Concatenate values to form joint levels of categories" in the article, "Visualize an ANOVA with two-way interactions." The article shows how to use CATX to combine the levels and PROC FORMAT to provide labels for the joint levels.



Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg



Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 3 in conversation