Presentation is loading. Please wait.

Presentation is loading. Please wait.

Kriss Harris, SAS Programmer, SAS Specialists Limited

Similar presentations


Presentation on theme: "Kriss Harris, SAS Programmer, SAS Specialists Limited"— Presentation transcript:

1 Kriss Harris, SAS Programmer, SAS Specialists Limited
Animate your Data! 1/12/2019 Kriss Harris, SAS Programmer, SAS Specialists Limited Kriss Harris worked at GlaxoSmithKline for almost 6 years from 2005 to 2011 as a Statistician supporting drug discovery. Whilst at GSK he developed an increasing passion for teaching and taught SAS Graphics to SAS Programmers, Statisticians and Scientists. Since then Kriss has moved on to become an independent Statistical Programmer and has consulted at Eli Lilly and Eisai. Currently Kriss is consulting at Eli Lilly supporting early phase Oncology.

2 Animate your Data! 1/12/2019 Richann Watson, Statistical Programmer and CDISC Consultant, DataRich Consulting Richann Watson is an independent statistical programmer and CDISC consultant. She has been using SAS since She has worked on various therapeutic areas including Oncology and Diabetes. She is also a member of the CDISC ADaM team and various sub-teams. In addition, she is the chairperson for the local SAS user group in her area and is actively involved with SAS Global Forum, PharmaSUG, MWSUG and other SAS User Groups.

3 1/12/2019 Animate your Data! Kriss Harris and Richann Watson

4 Agenda 1/12/2019 Show you how to produce animations

5 Agenda 1/12/2019 Show you how to produce smooth animations

6 Why use Animation? You can understand and interpret your data.
1/12/2019 You can understand and interpret your data. You can quickly get an idea of the number of subjects that had abnormal laboratory results at each visit. You are also able to easily determine the adverse events each subject had and the duration of the adverse event. You can monitor blood pressure over time by treatment. You can easily discern a dip or a spike in someone’s heart rate. Basic / general code needed to produce an animated graph

7 How to Animate 1/12/2019 ods printer file="C:\animation.gif"; options printerpath=gif animation=start animduration=0.5 animloop=yes noanimoverlay; proc sgrender data=<data-set-name> template=<template-name>; <other optional statements>; run; options printerpath=gif animation=stop; ods printer close; How to animate. To animate, there are essentially 5 sections that you need to bring together. The first and last section opens and closes the Printer Output Delivery System and this is where you specify the location of your animation. This works quite similar to ODS RTF file and ODS PDF file. The second and fourth section specify the animation to start and stop. And this is where you would include the animation options such as the duration of the each frame, or the output type. The third section is where you specify the code to create your plots, which will end up being animated. In this example we are using SGRENDER but we could use the other SG Procedures such as SGPLOT, SGSCATTER or SGPANEL. Because we are using SGRENDER that means that we have also created a template for the graph using GTL.

8 How to Animate proc template; define statgraph <template-name>;
1/12/2019 /* define template here */ ods printer file="C:\animation.gif"; options printerpath=gif animation=start animduration=0.5 animloop=yes noanimoverlay; /* or could define the template here */ proc sgrender data=<data-set-name> template=<template-name>; <other optional statements>; run; options printerpath=gif animation=stop; ods printer close; /* define template here */ ods printer file="C:\animation.gif"; options printerpath=gif animation=start animduration=0.5 animloop=yes noanimoverlay; /* or could define the template here */ proc sgrender data=<data-set-name> template=<template-name>; <other optional statements>; run; options printerpath=gif animation=stop; ods printer close; /* define template here */ ods printer file="C:\animation.gif"; options printerpath=gif animation=start animduration=0.5 animloop=yes noanimoverlay; /* or could define the template here */ proc sgrender data=<data-set-name> template=<template-name>; <other optional statements>; run; options printerpath=gif animation=stop; ods printer close; /* define template here */ ods printer file="C:\animation.gif"; options printerpath=gif animation=start animduration=0.5 animloop=yes noanimoverlay; /* or could define the template here */ proc sgrender data=<data-set-name> template=<template-name>; <other optional statements>; run; options printerpath=gif animation=stop; ods printer close; proc template; define statgraph <template-name>; begingraph / <options>; <GTL statements>; endgraph; end; run; Previous slide we showed the basic code. Here we show that some where prior to PROC SGRENDER we need to define the template. This can be done before or after the options statements as long as it is done prior to PROC SGRENDER. So let’s step through the process ANIMA1: Need to define the location where the graph will reside and the necessary options. ANIMA2: The following options need to be specified in order to produce an animated graph. Even need to specifying options after the rendering of the graph to stop the production of the animated graph. ANIMA3: Prior to render the graph the template needs to be defined. ANIMA4: Render the graph. Be sure to specify the correct data set and the correct template.

9 Animating Boxplot of Laboratory Results

10 Example 1 – Animated Boxplot of Lab Results
1/12/2019 Creatinine was selected The data here shows the laboratory results. One laboratory parameter has been selected and that is Creatinine (umol/L) There are three treatments in this data Placebo, Xanomeline High Dose and the Low Dose. In the data lab measurements were done approximately every two weeks. The standard normal lower and higher reference ranges for each gender for the Creatinine parameter is also shown. The Data

11 Example 1 – Animated Boxplot of Lab Results
1/12/2019 Number of subjects calculated at each visit for each treatment * Adding on n numbers; proc sql; create table lab_data_with_n as select *, count(distinct usubjid) as nobs_subject_visit from lab_data group by trtan, avisitn, sex; quit; The data was also modified to add on the Number of subjects for each lab parameter, treatment group and visit. This is because we want to display this information on the bottom of the graphs. So we used Proc SQL to count the number of patients for us. We could have used proc univariate or proc means if we wanted to also. Data Manipulations

12 Example 1 – Animated Boxplot of Lab Results
1/12/2019 proc template; define statgraph boxplot_template_sex; dynamic _byval_ _byval2_ _byval4_ upperlim lowerlim; begingraph; entrytitle halign = center _byval_ ":" " Sex = " _byval2_ " and Visit = " _byval4_; layout overlay / yaxisopts=(linearopts=(viewmin=60 viewmax=180 tickvaluesequence=(start=60 end=180 increment=30))); boxplot x = trtan y = aval / group = trtan groupdisplay=cluster; referenceline y=lowerlim / lineattrs=(pattern=2); referenceline y=upperlim / lineattrs=(pattern=2); innermargin; axistable x = trtan value = nobs_subject_visit / stat=mean label= "n" valueattrs=(size=9); endinnermargin; endlayout ; endgraph; end; run; Using GTL we created the template that will be used to produce our graph. There are 5 dynamic variables in this template. The first three _byval_ _byval2_ and _byval4_ will store the values of the variables which are used in the by statement. The variables used are Parameter, Gender and Visit. The other two dynamic variables upperlim and lowerlin are used to specify the standard normal lower and upper ranges. The entrytitle statement lets us identify the plot. For example it is used to display the lab parameter, gender and visit. The overlay layout was used as we only wanted “one graph per page” or we can say “one graph per frame”. The boxplot statement is used to produce the boxplot. The group = trtan option is used to display the boxplot of the three treatment groups. The referenceline statements produce the lower and upper standard normal reference ranges. The axistable is used to display the number of subjects that are in each parameter, gender and treatment. First Create the Template with Graph Template Language (GTL)

13 Example 1 – Animated Boxplot of Lab Results
1/12/2019 begingraph; entrytitle halign = center _byval_ ":" " Sex = " _byval2_ " and Visit = " _byval4_; layout overlay / yaxisopts=(linearopts=(viewmin=60 viewmax=180 tickvaluesequence=(start=60 end=180 increment=30))); boxplot x = trtan y = aval / group = trtan groupdisplay=cluster; referenceline y=lowerlim / lineattrs=(pattern=2); referenceline y=upperlim / lineattrs=(pattern=2); innermargin; axistable x = trtan value = nobs_subject_visit / stat=mean label= "n" valueattrs=(size=9); endinnermargin; endlayout; endgraph; First Create the Template with Graph Template Language (GTL)

14 Example 1 – Animated Boxplot of Lab Results
1/12/2019 options nobyline; options papersize=('8 in', '4.8 in') printerpath=gif animation=start animduration=0.5 animloop=yes noanimoverlay; ods printer file="&outpath\boxplotM1.gif"; ods graphics / width=8in height=4.8in imagefmt=gif; proc sgrender data = adlbc_all_n_gen template = boxplot_template_sex; where avisitn ne . and sex = "M"; by param sex avisitn avisit; dynamic upperlim = "a1hi" lowerlim = "a1lo"; format trtan trtfmt.; run; options printerpath=gif animation=stop; ods printer close; Here is the code and options that we used to produce the animation. First lets concentrate on the code before Proc SGRENDER. Animation Options and SGRENDER

15 Example 1 – Animated Boxplot of Lab Results
1/12/2019 options nobyline; options papersize=('8 in', '4.8 in') printerpath=gif animation=start animduration=0.5 animloop=yes noanimoverlay; ods printer file="&outpath\boxplotM1.gif"; ods graphics / width=8in height=4.8in imagefmt=gif; Options nobyline was used to remove the byline from the graph. This is because on the grapy we are using the Entrytitle statement to effectively produce are own byline. The paper size we used was 8 inches wide and 4.8 inches in height. The printerpath=gif produces the gif animation for us. Animation Options Before SGRENDER

16 Example 1 – Animated Boxplot of Lab Results
1/12/2019 proc sgrender data =adlbc_all_n_gen template = boxplot_template_sex; where avisitn ne . and sex = "M"; by param sex avisitn avisit; dynamic upperlim = "a1hi" lowerlim = "a1lo"; format trtan trtfmt.; run; SGRENDER

17 Example 1 – Animated Boxplot of Lab Results
1/12/2019 options printerpath=gif animation=stop; ods printer close; Animation Options After SGRENDER

18 Example 1 – Animated Boxplot of Lab Results
1/12/2019 Output

19 Example 1 – Animated Boxplot of Lab Results
1/12/2019 Open Program - Exercise 1 - Box Plot Animation Run all of the program and examine the output Modify the program so that the animation displays each visit for a longer duration.

20 Animating Scatterplot of Laboratory Results

21 Example 2 – Animated Scatterplot of Laboratory Results
1/12/2019 The Data Same data as in Example 1 But… Number of subjects with abnormal results were calculated at each visit for each treatment

22 Example 2 – Animated Scatterplot of Laboratory Results
1/12/2019 GTL layout overlay / yaxisopts=(linearopts=(viewmin=60 viewmax=180 tickvaluesequence=(start=60 end=180 increment=30))) xaxisopts=(type=discrete); scatterplot x = trtan y = aval / group = trtan groupdisplay = cluster jitter=auto jitteropts=(axis=x); referenceline y=lowerlim / lineattrs=(pattern=2); referenceline y=upperlim / lineattrs=(pattern=2); innermargin; axistable x=trtan value=nobs_abn_subject_visit /stat=mean label= "n" valueattrs=(size=9); endinnermargin; endlayout;

23 Example 2 – Animated Scatterplot of Laboratory Results
1/12/2019 Animation Options (the same as the Boxplot options) ods printer file="&outpath\scatterplotM1.gif"; ods graphics / width=8in height=4.8in imagefmt=gif; proc sgrender data = adlbc_all_abnormal_n_gen template=scatterplot_template_sex; where avisitn ne . and sex = "M"; by param sex avisitn avisit; dynamic upperlim = "a1hi" lowerlim = "a1lo"; format trtan trtfmt.; run; ods printer close;

24 Example 2 – Animated Scatterplot of Laboratory Results
1/12/2019 Output

25 Exercise 2 – Animated Scatterplot of Laboratory Results
1/12/2019 Open Program - Exercise 2 - Scatterplot Animation Run all of the program and examine the output Modify the program using the following instructions: Use ANIMLOOP=NO and output the animation REVERT TO ANIMLOOP = YES and change all instances of GIF to SVG, and then output the animation. Instead of displaying the number of subjects with abnormal visits, display the number of subjects at each visit for each treatment. Similar to the output in Example 1.

26 Exercise 2 – Animated Scatterplot of Laboratory Results
1/12/2019 Output of the Solution for Part 3 .GIF instead of .MOV is used here because it is sufficient to show that now the numbers of subjects at each visit is being displayed

27 Animating Blood Pressure Change Across Treatments

28 Example 3 – Change in Blood Pressure Across Treatments
1/12/2019 Animation is Not Time Dependent Sometimes what we want is not based only on time but based on a category as well We want to see how each treatment compares across time for both systolic and diastolic blood pressure. To include that information on the same graph would require a different set of line segments and / or different colors to distinguish between systolic and diastolic for each treatment. This could be hard to decipher. We could create individual pages and we just page through the individual pages, which is fine. But creating an animated graph will “page” through each treatment and allow us to see the differences.

29 Example 3 – Change in Blood Pressure Across Treatments
1/12/2019 The Data Using CDSIC Pilot Study, we use ADVS data set and take the determine the mean change from baseline (CHG) for each post baseline assessment regardless of the time point. This is what is used to as our input data set.

30 Comparison of Change in Blood Pressure
1/12/2019 Across Treatments begingraph; entrytitle halign=center _byval_; layout overlay / xaxisopts=(type=discrete discreteopts (tickvaluelist=('0' '2' '4' '6' '8' '12' '16' '20' '24' '26' '99'))) yaxisopts=(linearopts=(viewmin=-20 viewmax=2)); seriesplot x=AVISITN y=mean / display=all group=PARAMCD datalabel=n name="prm"; scatterplot x=AVISITN y=mean / group=PARAMCD yerrorupper=eval(mean+se) yerrorlower=eval(mean-se); discretelegend "prm" / across=2 location=outside; endlayout; endgraph; Note that options and SGRENDER are not shown since similar to other examples ANIMA1: Only display specific values on the x-axis ANIMA2: Series plot produces a plot of the mean change from baseline for each visit connected by a line. The group option groups the mean change by parameter so that both systolic and diastolic can be displayed on the same plot. The datalabel option allows us to place the subject count for each visit. The name option will be used for creating the legend so that we can tell what is systolic and what is diastolic. ANIMA3: Scatterplot utilizes the yerrorupper and yerrorlower to draw the whisker plots. It is going to draw the whisker plots based on the formula that is provided this allows it to be a dynamic value that is based on the data rather than hardcoded. ANIMA4: By providing a name to the seriesplot we are able to reference it later within the procedure to produce a legend that will help us to distinguish between systolic and diastolic. Prior to rendering the figure, the means and SE at each visit for each parameter needs to be determined.

31 Example 3 – Change in Blood Pressure Across Treatments
1/12/2019 Output

32 Exercise 3 – Animated Series Plot of Change in Blood Pressure
1/12/2019 Open Program - Exercise 3 - Series Animation - CHG Run all of the program and examine the output Modify the program using the following instructions: Calculate the mean and standard error by treatment and sex Display the figure by treatment and sex. Graph label should be in the following format

33 Creating Smooth Animations - Scatterplot Example
Interpolation Creating Smooth Animations - Scatterplot Example

34 Why Interpolate? 1/12/2019

35 Add visits in between the original visits
How to Interpolate? 1/12/2019 First step is determine variable that will drive animation (e.g., AVISITN) There are 10 visits Add visits in between the original visits

36 How to Interpolate? 1/12/2019 Merge the data together so that the new visit records are between the existing visit records proc expand data=proc_expand_data out=LinInterp_scatter; by usubjid param sex trtan; convert aval=linear / method=join; id id; run; Proc EXPAND will interpolate these values It’s not possible to use Proc EXPAND with SAS UE

37 This will be filled down by using data step
How to Interpolate? 1/12/2019 Interpolated Data set This will be filled down by using data step

38 Example 4 - Scatterplot Animation with Linear Interpolation
1/12/2019 GTL This example uses GTL code similar to Example 2 layout overlay / yaxisopts=(linearopts=(viewmin=60 viewmax=180 tickvaluesequence=(start=60 end=180 increment=30))) xaxisopts=(type=discrete); scatterplot x = trtan y = aval / group = trtan groupdisplay = cluster jitter=auto jitteropts=(axis=x); referenceline y=lowerlim / lineattrs=(pattern=2); referenceline y=upperlim / lineattrs=(pattern=2); endlayout;

39 Example 4 - Scatterplot Animation with Linear Interpolation
1/12/2019 Animation options options papersize=('8 in', '4.8 in')printerpath=gif animation=start animduration=0.16 animloop=yes noanimoverlay nonumber; Animation duration has been decreased compared to Example 2, because now there are a lot more frames, and we want to have a smooth animation.

40 Exercise 4 - Scatterplot Animation with Linear Interpolation
1/12/2019 Open Program - Exercise 4 - Scatterplot Animation Linear Interpolation Run all of the program and examine the output Modify the program so that there are 9 visits between each of the original visits. i.e. 2 – 4, should now be 2, 2.2, 2.4, 2.6, 2.8, 3.0, 3.2, 3.4, 3.6, 3.8 and 4. Will show the solutions to the Exercise in SAS

41 Creating Smooth Animations – Adverse Events (AEs) over time Example
Interpolation Creating Smooth Animations – Adverse Events (AEs) over time Example

42 Example 5 - AEs over time by Baseline Laboratory Results
1/12/2019 A great way to assess the AE counts and visualize the relationship

43 Example 5 - AEs over time by Baseline Laboratory Results
1/12/2019 Data sets Week AE started was calculated ADAE dataset TRTEMFL = “Y” No. of AEs for each week were calculated Then Cumulative Counts were calculated Cumulative Counts ranged from Week 0 to Week 28

44 Example 5 - AEs over time by Baseline Laboratory Results
1/12/2019 Final Data set 4 visits were added in-between “original visits” Interpolated Counts

45 Example 5 - AEs over time by Baseline Laboratory Results
1/12/2019 GTL begingraph / designwidth = 1200px designheight = 960px; entrytitle textattrs = (size = 18pt) halign = center "Week = "_byval_; layout datapanel classvars= (trtan) / headerlabeldisplay=value headerlabelattrs=(size = 15pt) columns = 3 rows = 1 rowaxisopts=(label = "TEAE counts" labelattrs=(size = 18pt) tickvalueattrs=(size = 16pt) linearopts=(viewmin=0 viewmax=25 tickvaluesequence=(start=0 end=25 increment=5))) columnaxisopts = (label = "Baseline Creatinine (umol/L)" labelattrs=(size = 18pt) tickvalueattrs=(size = 16pt)); layout prototype; scatterplot x = baseline_creatinine y = aval / group = trtan markerattrs = (size = 15px symbol=circlefilled); endlayout; endgraph; Mention about DATAPANEL layout

46 Example 5 - AEs over time by Baseline Laboratory Results
1/12/2019 Animation Options ods printer file="&outpath\ae_anim1_scat.gif"; options papersize=('8 in', '6.4 in') printerpath=gif animation=start animduration=0.13 animloop=yes noanimoverlay nonumber; ods graphics / reset = all width=8in height=6.4in imagefmt=png; proc sgrender data = final_dataset template= aedecod_anim_scat; by avisitn; format trtan trtfmt.; run; ods graphics / reset = all; options printerpath=gif animation=stop; ods printer close;

47 Exercise 5 - AEs over time by Baseline Laboratory Results
1/12/2019 Open Program - Exercise 5 - TEAE Animation Linear Interpolation Run all of the program and examine the output Modify the program: to use a different variable of your choice on the x-axis. to use the animoverlay option instead of noanimoverlay Will show the solutions to the Exercise in SAS

48 Electrocardiogram (ECG) Heart Rate over Time
Expansion Electrocardiogram (ECG) Heart Rate over Time

49 Example 6 – ECG Heart Rate over Time
1/12/2019 On TV and in real life, we’ve all seen a heart rate monitor that display’s how someone heart is beating over time. How is this heart rate monitor display achieved with SAS?

50 Example 6 – ECG Heart Rate over Time
1/12/2019 Data sets A drawing effect was achieved by keeping records from previous animation and adding the heart rate information of the current visit. This was achieved by grouping the animations every 3 seconds. There is 15 minutes of data and so we thought to speed the animation up 6 times faster. Each row represents 0.5 seconds Animation Series 2 Animation Series 1

51 Exercise 6 – ECG Heart Rate over Time
1/12/2019 Open Program - Exercise 6 -ECG Animation v2 Fill in the missing variables, wherever you see the text <xxxx?>, so that you can produce the plot below

52 Conclusions 1/12/2019 Animations can be done quite easily with SAS 9.4. All that is needed is to wrap the appropriate OPTIONS and the ODS PRINTER statements around the plots. Smoother animations can be created by using Proc EXPAND to interpolate results in between the visits (if there are not enough visits for smooth animation), and then producing the animation on the data set which contains interpolated results. A drawing effect can be achieved by grouping data into series and retaining a duplicate of set of records for each subsequent series.

53 Contact Information 1/12/2019 Kriss Harris SAS Specialists Limited Richann Watson DataRich Consulting

54 Your Feedback Counts! 1/12/2019 Don't forget to complete the feedback form please. Your feedback is valuable!

55 References 1/12/2019 CDISC. (2013). CDISC. Retrieved from SDTM/ADaM Pilot Project: Harris, K. (2016). Animate Your Safety Data. PharmaSUG China. Beijing: PharmaSUG. Harris, K. (2017). Hands-On Graph Template Language (GTL): Part A. SAS Global Forum. Denver: SAS Global Forum. Harris, K., & Watson, R. (2018). Great Time to Learn GTL. PharmaSUG. Seattle: PharmaSUG. Matange, S. (n.d.). Animation using SGPLOT. Retrieved from Graphically Speaking: McCarthy, A. (2017). Using Animated Graphics to Show PKPD Relationships in SAS 9.4. PharmaSUG (pp. 4-6). Baltimore: PharmaSUG.

56 Acknowledgements 1/12/2019 We will like to acknowledge Tao Shu, Lixiang Larry Liu, and Jianfei Jiang for introducing us to the Cumulative TEAE plot.

57 Questions? 1/12/2019


Download ppt "Kriss Harris, SAS Programmer, SAS Specialists Limited"

Similar presentations


Ads by Google