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

I want to make a graph that is density (PCRQ) by study day (DAY) with a line for each subject (ID), and I want the graph for each CHMI. Something like below, but I need to account for multiple measurements within the same study day. I was told to jitter the graph to account for the different times, but I am not very familiar with how that works. Example code seems to jitter based on one of the axis, but I have time separate from day. Do I need to combine my day and time columns? If so, what is the best way to go about that? Study day 1, 2, etc. will not be the same date for everyone, so I don't think a DATETIME format would work. Additionally, how do you assign specific colors to each subject? Since there will be multiple graphs (one for each CHMI), I want to keep consistent colors for each subject.

 

data have;
 input id $ chmi day time $ pcrr pcrq @@;
 cards;
 A	1	6	08:55	1	33.86
 A	1	9	10:30	1	36.21
 A	1	12	07:57	0	1
 A	1	15	09:13	0	1
 A	2	6	12:10	1	27.9
 A	2	9	02:50	0	1
 A	2	12	06:00	0	1
 A	3	6	09:21	0	1
 A	3	9	13:56	1	30.56
 A	3	9	15:29	1	33.27
 A	3	12	15:09	1	32.87
 A	3	15	12:42	0	1
 B	1	6	09:17	1	30.81
 B	1	6	13:12	1	29.66
 B	1	9	10:49	1	35.08
 B	1	12	11:03	0	1
 B	1	15	18:24	0	1
 B	2	6	17:31	1	28.56
 B	2	9	16:01	1	34.01
 B	2	12	17:23	1	33.56
 B	2	15	09:00	0	1
 B	3	6	17:55	1	28.63
 B	3	9	09:32	1	31.97
 B	3	9	10:54	1	30.04
 B	3	12	07:23	1	27.68
 B	3	15	11:31	0	1
 ;
run;
proc sgplot data= have (where= (chmi= 1));
 series x= day y= pcrq / group= id;
 scatter x= day y= pcrq / group= id jitter= uniform;
run;

Desired output graph similar to:

mariko5797_0-1645629195678.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
DanH_sas
SAS Super FREQ

Here are some thoughts for you:

1. Use and "attributes map" to associate visual attributes (like color) to a group value (see the code below).

2. You can use a BY-group with SGPLOT to get a graph per CHMI value (sort your data by CHMI). You might also like to use SGPANEL to see them together for comparison (see the code below)

3. I would use a data step to take the day and time values and turn them into a factional day value (e.g. 1.15, 1.5, etc). You will then get the "jittering" effect you want. Use the INTEGER option on the XAXIS or COLAXIS statements to make sure the axis shows the days as whole numbers.

 

Hope this helps!

Dan

 

data attrmap;
retain id "patient";
length linecolor $ 6 markercolor $ 6;
input value $ linecolor $ markercolor $;
cards;
A purple purple
B green  green
;
run;

proc sgpanel data=have dattrmap=attrmap;
panelby chmi / layout=rowlattice;
 colaxis integer;
 series x= day y= pcrq / group= id attrid=patient markers;
run;

View solution in original post

2 REPLIES 2
sbxkoenk
SAS Super FREQ

I have moved your post to the "Graphics Programming" board.

Koen

DanH_sas
SAS Super FREQ

Here are some thoughts for you:

1. Use and "attributes map" to associate visual attributes (like color) to a group value (see the code below).

2. You can use a BY-group with SGPLOT to get a graph per CHMI value (sort your data by CHMI). You might also like to use SGPANEL to see them together for comparison (see the code below)

3. I would use a data step to take the day and time values and turn them into a factional day value (e.g. 1.15, 1.5, etc). You will then get the "jittering" effect you want. Use the INTEGER option on the XAXIS or COLAXIS statements to make sure the axis shows the days as whole numbers.

 

Hope this helps!

Dan

 

data attrmap;
retain id "patient";
length linecolor $ 6 markercolor $ 6;
input value $ linecolor $ markercolor $;
cards;
A purple purple
B green  green
;
run;

proc sgpanel data=have dattrmap=attrmap;
panelby chmi / layout=rowlattice;
 colaxis integer;
 series x= day y= pcrq / group= id attrid=patient markers;
run;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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
  • 912 views
  • 3 likes
  • 3 in conversation