BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
cmendoza87
Obsidian | Level 7

Hello,

 

I am trying to use proc sgplot with scatter and series to create a plot that shows differences between two time points for each group and would like to be able to connect the dots if possible.

 

Code:

DATA Change_all2;
INPUT Time $ Group $ Variable2 $ Estimate Lower Upper;
DATALINES;
Baseline Overall eGFR 109.97 109.56 110.38
Baseline No_DS eGFR 109.70 109.18 110.22
Baseline DS eGFR 110.72 110.15 111.29
Baseline DS_Infreq eGFR 111.19 110.54 111.84
Baseline DS_Freq eGFR 109.32 108.32 110.32
Baseline DS_Bot eGFR 111.37 110.50 112.24
Baseline DS_NVNM eGFR 110.81 109.93 111.70
Baseline DS_Vit_Min eGFR 109.80 108.79 110.80
Baseline DS_NonNeph eGFR 110.59 109.99 111.20
Baseline DS_Neph eGFR 111.46 110.38 112.55
Visit2 Overall eGFR 106.58 106.13 107.03
Visit2 No_DS eGFR 105.97 105.38 106.56
Visit2 DS eGFR 107.55 106.88 108.22
Visit2 DS_Infreq eGFR 107.89 107.15 108.64
Visit2 DS_Freq eGFR 107.09 105.70 108.48
Visit2 DS_Bot eGFR 108.23 107.23 109.22
Visit2 DS_NVNM eGFR 107.40 106.27 108.54
Visit2 DS_Vit_Min eGFR 106.47 105.30 107.64
Visit2 DS_NonNeph eGFR 107.30 106.55 108.04
Visit2 DS_Neph eGFR 108.91 107.80 110.02

;

RUN;

 

PROC SGPLOT DATA=Change_all2;
WHERE Variable2 = "eGFR";
LABEL Estimate = "Age- and Sex-Adjusted ACR and eGFR";
SCATTER Y=Estimate X=Group / GROUP=Time GROUPDISPLAY=CLUSTER YERRORLOWER=Lower YERRORUPPER=Upper JITTER;
SERIES Y=Estimate X=Group / GROUP=Time GROUPDISPLAY=CLUSTER;
XAXIS TYPE=DISCRETE;
TITLE "Baseline to Visit 2 eGFR by Group";
RUN;

cmendoza87_0-1658074365435.png

Ideally, I would like there to be a line from baseline to visit 2 for each group instead of what is shown above but I am not sure how to make that happen. 

 

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

OK. As you said, I think you need change your data value .

 

DATA Change_all2;
INPUT Time $ Group Group2 Variable2 $ Estimate Lower Upper;
DATALINES;
Baseline 1 0.6 eGFR 109.97 109.56 110.38
Baseline 2 1.6 eGFR 109.70 109.18 110.22
Baseline 3 2.6 eGFR 110.72 110.15 111.29
Baseline 4 3.6 eGFR 111.19 110.54 111.84
Baseline 5 4.6 eGFR 109.32 108.32 110.32
Baseline 6 5.6 eGFR 111.37 110.50 112.24
Baseline 7 6.6 eGFR 110.81 109.93 111.70
Baseline 8 7.6 eGFR 109.80 108.79 110.80
Baseline 9 8.6 eGFR 110.59 109.99 111.20
Baseline 10 9.6 eGFR 111.46 110.38 112.55
Visit2 1 1.4 eGFR 106.58 106.13 107.03
Visit2 2 2.4 eGFR 105.97 105.38 106.56
Visit2 3 3.4 eGFR 107.55 106.88 108.22
Visit2 4 4.4 eGFR 107.89 107.15 108.64
Visit2 5 5.4 eGFR 107.09 105.70 108.48
Visit2 6 6.4 eGFR 108.23 107.23 109.22
Visit2 7 7.4 eGFR 107.40 106.27 108.54
Visit2 8 8.4 eGFR 106.47 105.30 107.64
Visit2 9 9.4 eGFR 107.30 106.55 108.04
Visit2 10 10.4 eGFR 108.91 107.80 110.02
;
RUN;

 

PROC SGPLOT DATA=Change_all2 noautolegend;
WHERE Variable2 = "eGFR";
LABEL Estimate = "Age- and Sex-Adjusted ACR and eGFR";
series Y=Estimate X=Group2/group=group lineattrs=(color=gray ) ;

SCATTER Y=Estimate X=Group2 / GROUP=Time YERRORLOWER=Lower YERRORUPPER=Upper JITTER ;
XAXIS   values=(0 to 11 by 1)  fitpolicy=rotate display=(nolabel)
valuesdisplay=(' ' 'Overall' 'No_DS' 'DS' 'DS_Infreq' 
 'DS_Freq' 'DS_Bot' 'DS_NVNM' 'DS_Vit_Min' 'DS_NonNeph' 'DS_Neph' ' ');
TITLE "Baseline to Visit 2 eGFR by Group";
RUN;
 
 
 

 

 

View solution in original post

7 REPLIES 7
ballardw
Super User

Describe exactly what values of what variables are to be used to connect a baseline to a visit value.

 

If you say "group" you are very likely to have a result where the connection overwrites your error bars making them very hard to see

cmendoza87
Obsidian | Level 7

I would like to connect: 109.97 to 106.58, 109.70 to 105.97, 110.72 to 107.55, 111.19 to 107.89, 109.32 to 107.09, 111.37 to 108.23, 110.81 to 107.40, 109.80 to 106.47, 110.59 to 107.30, 111.46 to 108.91.

 

Ideally, the points would be slightly jittered so that the error bars could still show but that may not be possible.

Ksharp
Super User

You want this one ?

 

DATA Change_all2;
INPUT Time $ Group $ Variable2 $ Estimate Lower Upper;
DATALINES;
Baseline Overall eGFR 109.97 109.56 110.38
Baseline No_DS eGFR 109.70 109.18 110.22
Baseline DS eGFR 110.72 110.15 111.29
Baseline DS_Infreq eGFR 111.19 110.54 111.84
Baseline DS_Freq eGFR 109.32 108.32 110.32
Baseline DS_Bot eGFR 111.37 110.50 112.24
Baseline DS_NVNM eGFR 110.81 109.93 111.70
Baseline DS_Vit_Min eGFR 109.80 108.79 110.80
Baseline DS_NonNeph eGFR 110.59 109.99 111.20
Baseline DS_Neph eGFR 111.46 110.38 112.55
Visit2 Overall eGFR 106.58 106.13 107.03
Visit2 No_DS eGFR 105.97 105.38 106.56
Visit2 DS eGFR 107.55 106.88 108.22
Visit2 DS_Infreq eGFR 107.89 107.15 108.64
Visit2 DS_Freq eGFR 107.09 105.70 108.48
Visit2 DS_Bot eGFR 108.23 107.23 109.22
Visit2 DS_NVNM eGFR 107.40 106.27 108.54
Visit2 DS_Vit_Min eGFR 106.47 105.30 107.64
Visit2 DS_NonNeph eGFR 107.30 106.55 108.04
Visit2 DS_Neph eGFR 108.91 107.80 110.02

;

RUN;

 

PROC SGPLOT DATA=Change_all2 noautolegend;
WHERE Variable2 = "eGFR";
LABEL Estimate = "Age- and Sex-Adjusted ACR and eGFR";
series Y=Estimate X=Group/group=group lineattrs=(color=grey pattern=dash) ;

SCATTER Y=Estimate X=Group / GROUP=Time GROUPDISPLAY=overlay YERRORLOWER=Lower YERRORUPPER=Upper JITTER;
SERIES Y=Estimate X=Group / GROUP=Time GROUPDISPLAY=overlay;
XAXIS TYPE=DISCRETE;
TITLE "Baseline to Visit 2 eGFR by Group";
RUN;

Ksharp_0-1658148174385.png

 

cmendoza87
Obsidian | Level 7

Thank you, I was hoping for it to look something like this, but I think I would need to redo my datalines? Or is there a way to separate each group (i.e. overall, no_DS, etc) into baseline and visit 2?

cmendoza87_0-1658156584630.png

Thank you so much for your help!

Ksharp
Super User

OK. As you said, I think you need change your data value .

 

DATA Change_all2;
INPUT Time $ Group Group2 Variable2 $ Estimate Lower Upper;
DATALINES;
Baseline 1 0.6 eGFR 109.97 109.56 110.38
Baseline 2 1.6 eGFR 109.70 109.18 110.22
Baseline 3 2.6 eGFR 110.72 110.15 111.29
Baseline 4 3.6 eGFR 111.19 110.54 111.84
Baseline 5 4.6 eGFR 109.32 108.32 110.32
Baseline 6 5.6 eGFR 111.37 110.50 112.24
Baseline 7 6.6 eGFR 110.81 109.93 111.70
Baseline 8 7.6 eGFR 109.80 108.79 110.80
Baseline 9 8.6 eGFR 110.59 109.99 111.20
Baseline 10 9.6 eGFR 111.46 110.38 112.55
Visit2 1 1.4 eGFR 106.58 106.13 107.03
Visit2 2 2.4 eGFR 105.97 105.38 106.56
Visit2 3 3.4 eGFR 107.55 106.88 108.22
Visit2 4 4.4 eGFR 107.89 107.15 108.64
Visit2 5 5.4 eGFR 107.09 105.70 108.48
Visit2 6 6.4 eGFR 108.23 107.23 109.22
Visit2 7 7.4 eGFR 107.40 106.27 108.54
Visit2 8 8.4 eGFR 106.47 105.30 107.64
Visit2 9 9.4 eGFR 107.30 106.55 108.04
Visit2 10 10.4 eGFR 108.91 107.80 110.02
;
RUN;

 

PROC SGPLOT DATA=Change_all2 noautolegend;
WHERE Variable2 = "eGFR";
LABEL Estimate = "Age- and Sex-Adjusted ACR and eGFR";
series Y=Estimate X=Group2/group=group lineattrs=(color=gray ) ;

SCATTER Y=Estimate X=Group2 / GROUP=Time YERRORLOWER=Lower YERRORUPPER=Upper JITTER ;
XAXIS   values=(0 to 11 by 1)  fitpolicy=rotate display=(nolabel)
valuesdisplay=(' ' 'Overall' 'No_DS' 'DS' 'DS_Infreq' 
 'DS_Freq' 'DS_Bot' 'DS_NVNM' 'DS_Vit_Min' 'DS_NonNeph' 'DS_Neph' ' ');
TITLE "Baseline to Visit 2 eGFR by Group";
RUN;
 
 
 

 

 

cmendoza87
Obsidian | Level 7

Thank you so much, this worked perfectly!

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 7 replies
  • 1991 views
  • 2 likes
  • 3 in conversation