Data visualization with SAS programming

Plotting line graph for 2 variable per patient

Reply
Contributor
Posts: 21

Plotting line graph for 2 variable per patient

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: 

iddate_timevolume_1volume_2
14/19/14 9:51 PM  
14/19/14 9:56 PM41.756.20
14/20/14 12:53 PM50.825.00
14/21/14 8:38 PM51.774.70
14/22/14 5:51 PM  
24/23/14 1:34 PM55.186.00
27/3/14 12:50 AM14.312.40
27/3/14 3:34 PM12.680.80
27/3/14 9:00 PM10.990.90
27/4/14 3:30 PM8.161.20
SAS Super FREQ
Posts: 4,110

Re: Plotting line graph for 2 variable per patient

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;
Contributor
Posts: 21

Re: Plotting line graph for 2 variable per patient

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!

SAS Super FREQ
Posts: 4,110

Re: Plotting line graph for 2 variable per patient

- 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;

Contributor
Posts: 21

Re: Plotting line graph for 2 variable per patient

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:

 

iddate_timevolume_1volume_2group
14/19/14 9:51 PM  placebo
14/19/14 9:56 PM41.756.20placebo
14/20/14 12:53 PM50.825.00placebo
14/21/14 8:38 PM51.774.70placebo
14/22/14 5:51 PM  placebo
24/23/14 1:34 PM55.186.00drug
27/3/14 12:50 AM14.312.40drug
27/3/14 3:34 PM12.680.80drug
27/3/14 9:00 PM10.990.90drug
27/4/14 3:30 PM8.161.20

drug

SAS Super FREQ
Posts: 4,110

Re: Plotting line graph for 2 variable per patient

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;

 

Ask a Question
Discussion stats
  • 5 replies
  • 104 views
  • 0 likes
  • 2 in conversation