Hi. I have about total of 500 patient and each patient has multiple volumes per time. So the dataset is the long format (multiple records per patient instead of one patient per row).
The x-axis should be the date_time
The y-axis should be 1) volume_1 line connected and 2) volume_2 connected
However, I would like to export each patient in one PDF file or multiple PDF. But I am really struggling with it. I tried proc plot etc, but no luck. Really appreciate the help! Thank you!
Here is the sample table:
id | date_time | volume_1 | volume_2 |
1 | 4/19/14 9:51 PM | ||
1 | 4/19/14 9:56 PM | 41.75 | 6.20 |
1 | 4/20/14 12:53 PM | 50.82 | 5.00 |
1 | 4/21/14 8:38 PM | 51.77 | 4.70 |
1 | 4/22/14 5:51 PM | ||
2 | 4/23/14 1:34 PM | 55.18 | 6.00 |
2 | 7/3/14 12:50 AM | 14.31 | 2.40 |
2 | 7/3/14 3:34 PM | 12.68 | 0.80 |
2 | 7/3/14 9:00 PM | 10.99 | 0.90 |
2 | 7/4/14 3:30 PM | 8.16 | 1.20 |
So you want 500 plots, where each plot is for a patient and each plot shows volume_1 and volume_2?
If so, try
proc sgplot data=Have;
by id;
series x=date_time y=volume_1;
series x=date_time y=volume_2;
run;
Here is some sample data that we all can run, in case you have additional questions:
proc sgplot data=sashelp.stocks;
by stock;
series x=Date y=open;
series x=Date y=close;
run;
Thank you so much! It works!! Couple more questions
- Is there any way that I can include the randomization_date and treatment group on the graph title or something? I don't need on the line graph but next the to ID name?
- Also right now, my y axis is showing volume_1. How do I relabel as "Volume" only? Since this is a line graph, is there any way I can get scatter dot?
Thank you!
- Is there any way that I can include the randomization_date and treatment group on the graph title or something? I don't need on the line graph but next the to ID name?
Please post example data.
- Also right now, my y axis is showing volume_1. How do I relabel as "Volume" only? Since this is a line graph, is there any way I can get scatter dot?
Yes to both questions.
- Add a YAXIS statement and use the LABEL= option, such as
YAXIS label="Volume";
- To get the scatter plot, use the SCATTER statement and put the name of your observed response on the Y= option:
scatter x=date_time y=NAME_OF_OBSERVED_VARIABLE;
Thanks so much. I really appreciate it.
So basically I want scatter line connect plot. X-axis = date_time and y-axis should be volume_1 and volume_2. Each graph should show id and group name. The y-axis should say: "Volume'
Something like this:
id | date_time | volume_1 | volume_2 | group |
1 | 4/19/14 9:51 PM | placebo | ||
1 | 4/19/14 9:56 PM | 41.75 | 6.20 | placebo |
1 | 4/20/14 12:53 PM | 50.82 | 5.00 | placebo |
1 | 4/21/14 8:38 PM | 51.77 | 4.70 | placebo |
1 | 4/22/14 5:51 PM | placebo | ||
2 | 4/23/14 1:34 PM | 55.18 | 6.00 | drug |
2 | 7/3/14 12:50 AM | 14.31 | 2.40 | drug |
2 | 7/3/14 3:34 PM | 12.68 | 0.80 | drug |
2 | 7/3/14 9:00 PM | 10.99 | 0.90 | drug |
2 | 7/4/14 3:30 PM | 8.16 | 1.20 | drug |
You should really make a minimal effort to read the documentation and try to modify the code yourself before you respond with more questions. We are here to help you learn, which happens best when you actively work through the questions you ask.
To answer your questions:
1. Sort your data: BY Group ID date_time;
2. Plot the data: BY Group ID;
3. Add the MARKERS option to the SERIES statements: SERIES x= ... y=... / MARKERS;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.