New SAS User

Completely new to SAS or trying something new with SAS? Post here for help getting started.
BookmarkSubscribeRSS Feed
radhikaa4
Calcite | Level 5

Hi

 

I am trying to create a time series plot by EACH subject so the output will show graphs for each individual for 3 variables of interest with multiple dates. Each dates have several indexes that I would like to show that too.

 

Here is the sample dataset:

 

subjectIDaaformGroupivisit_datebbcc
116Day 111/19/20158468
110Day 121/19/20159282
110Day 131/19/201510090
18Day 141/19/201510496
110Day 211/20/201510090
17Day 221/20/201510093
210Day 124/12/20168878
217Day 134/12/20168164
215Day 144/12/20168469
217Day 214/13/20169376
214Day 224/13/20168672
216Day 244/13/20167458

 

Here is the code I have so far

 

PROC SGPLOT data = have;

BY subjectID;

scatter x = visit_date y = aa;

scatter x = visit_date y = bb;

scatter x = visit_date y = cc;

series x = visit_date y = aa;

series x = visit_date y = bb;

series x = visit_date y = cc;

RUN;

 

However, In addition to the Visit_date, I would like to include "I" variable so to show how values changed within that same day

 

Any help would be great!!

 

Thank you

10 REPLIES 10
Reeza
Super User

Can you show, somehow, an example of what you're trying to achieve?

 


@radhikaa4 wrote:

Hi

 

I am trying to create a time series plot by EACH subject so the output will show graphs for each individual for 3 variables of interest with multiple dates. Each dates have several indexes that I would like to show that too.

 

Here is the sample dataset:

 

subjectID aa formGroup i visit_date bb cc
1 16 Day 1 1 1/19/2015 84 68
1 10 Day 1 2 1/19/2015 92 82
1 10 Day 1 3 1/19/2015 100 90
1 8 Day 1 4 1/19/2015 104 96
1 10 Day 2 1 1/20/2015 100 90
1 7 Day 2 2 1/20/2015 100 93
2 10 Day 1 2 4/12/2016 88 78
2 17 Day 1 3 4/12/2016 81 64
2 15 Day 1 4 4/12/2016 84 69
2 17 Day 2 1 4/13/2016 93 76
2 14 Day 2 2 4/13/2016 86 72
2 16 Day 2 4 4/13/2016 74 58

 

Here is the code I have so far

 

PROC SGPLOT data = have;

BY subjectID;

scatter x = visit_date y = aa;

scatter x = visit_date y = bb;

scatter x = visit_date y = cc;

series x = visit_date y = aa;

series x = visit_date y = bb;

series x = visit_date y = cc;

RUN;

 

However, In addition to the Visit_date, I would like to include "I" variable so to show how values changed within that same day

 

Any help would be great!!

 

Thank you


 

 

PeterClemmensen
Tourmaline | Level 20

What does i represent? should the distance between i=1 and i=2 be the same as between i=2 and i=4 within the same date? Or double distance?

radhikaa4
Calcite | Level 5

i is the index. for example, each "Day" has multiple entries and I want to show all i's across each day for each patient

PeterClemmensen
Tourmaline | Level 20

Just to get things started, here is what your data looks like and the SGPLOT Procedure

 

data have;
input subjectID $ aa formGroup $ i visit_date:mmddyy10. bb cc;
infile datalines dlm=',';
format visit_date mmddyy10.;
datalines;
1,16,Day 1,1,1/19/2015,84,68
1,10,Day 1,2,1/19/2015,92,82
1,10,Day 1,3,1/19/2015,100,90
1,8,Day 1,4,1/19/2015,104,96
1,10,Day 2,1,1/20/2015,100,90
1,7,Day 2,2,1/20/2015,100,93
2,10,Day 1,2,4/12/2016,88,78
2,17,Day 1,3,4/12/2016,81,64
2,15,Day 1,4,4/12/2016,84,69
2,17,Day 2,1,4/13/2016,93,76
2,14,Day 2,2,4/13/2016,86,72
2,16,Day 2,4,4/13/2016,74,58
;

proc sgplot data = have;
   by subjectid;
   series x = visit_date y = aa / markers;
   series x = visit_date y = bb / markers;
   series x = visit_date y = cc / markers;
run;

You can use the MARKERS Option in the Series Statement to create the markers instead of the Scatter Statement.

radhikaa4
Calcite | Level 5

Hi! Thank you. I think we are almost there. The marker is ovelaying different Indexes (which 'i' variable) on top of each other for each. Is there any way to show across ?

Reeza
Super User

Which dot do you want connected when you have multiple on a single day, first/last, some statistic? Do you want the average instead? 

 


@radhikaa4 wrote:

Hi! Thank you. I think we are almost there. The marker is ovelaying different Indexes (which 'i' variable) on top of each other for each. Is there any way to show across ?


 

radhikaa4
Calcite | Level 5
Hi. I would like to connect all dots.



If Patient #1 has 3 Day 1 values, 2 Day 2 values so I want to connect day 1 index 1 to be connected to day 1 index 2 to be connected to day 1 index 3 to be connected to day 2 index 1 to be connected to day 2 index 2


Ksharp
Super User

You want this ?

 

data have;
input subjectID $ aa formGroup $ i visit_date:mmddyy10. bb cc;
infile datalines dlm=',';
format visit_date mmddyy10.;
datalines;
1,16,Day 1,1,1/19/2015,84,68
1,10,Day 1,2,1/19/2015,92,82
1,10,Day 1,3,1/19/2015,100,90
1,8,Day 1,4,1/19/2015,104,96
1,10,Day 2,1,1/20/2015,100,90
1,7,Day 2,2,1/20/2015,100,93
2,10,Day 1,2,4/12/2016,88,78
2,17,Day 1,3,4/12/2016,81,64
2,15,Day 1,4,4/12/2016,84,69
2,17,Day 2,1,4/13/2016,93,76
2,14,Day 2,2,4/13/2016,86,72
2,16,Day 2,4,4/13/2016,74,58
;

proc sgpanel data=have;
panelby subjectID visit_date;
 series x = i y = aa / markers;
 series x = i y = bb / markers;
 series x = i y = cc / markers;
run;
radhikaa4
Calcite | Level 5
Thank you! This is really helpful. Is there any way that I can make one patient per graph and have all I's by visit dates in one graph? Thanks again!


Ksharp
Super User

This one ?

 

data have;
input subjectID $ aa formGroup $ i visit_date:mmddyy10. bb cc;
infile datalines dlm=',';
format visit_date mmddyy10.;
datalines;
1,16,Day 1,1,1/19/2015,84,68
1,10,Day 1,2,1/19/2015,92,82
1,10,Day 1,3,1/19/2015,100,90
1,8,Day 1,4,1/19/2015,104,96
1,10,Day 2,1,1/20/2015,100,90
1,7,Day 2,2,1/20/2015,100,93
2,10,Day 1,2,4/12/2016,88,78
2,17,Day 1,3,4/12/2016,81,64
2,15,Day 1,4,4/12/2016,84,69
2,17,Day 2,1,4/13/2016,93,76
2,14,Day 2,2,4/13/2016,86,72
2,16,Day 2,4,4/13/2016,74,58
;

proc sgpanel data=have;
by subjectID ;
panelby visit_date/onepanel layout=rowlattice novarname;
 series x = i y = aa / markers;
 series x = i y = bb / markers;
 series x = i y = cc / markers;
run;

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 10 replies
  • 5700 views
  • 0 likes
  • 4 in conversation