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

Hello SAS users,

 

I have data for different treatments that I would want to show on a trend line. The treatments are all categorical data and collected over 4-time points.

 

I want to plot the prevalence of use of each of the 8 treatments on the same graph and then calculate their P for trend. If the treatments are (yes vs. No), how do I go about plotting the graphs? I figured that I can calculate the P-for trend via Cockrahe Armitage. Does anyone have an idea how I can plot all treatments on the graph and not separately? The Excel sheet is attached 

ChuksManuel_0-1665002179591.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

What you show is pretty clearly not a data set. So show what the DATASET looks like.

It may not hurt to mention trend of what. You show Yes/No as text combining a count and a percentage. So do you want to show a trend of Yes or No? Of the count or the percentage.

 

An example of what a data set to graph should look like and how to plot that with Treatment as a group variable.

data example;
  input treatment $ year percent;
datalines;
a  2000  .15
a  2001  .16
a  2002  .18
a  2003  .117
b  2000  .25
b  2001  .28
b  2002  .26
b  2003  .27
;

proc sgplot data=example;
   series x=year y=percent /group=treatment;
   yaxis values=(0 to .5 by .1);
   format percent percent5.;
run;
/* or fit a line through the points but not connect*/ proc sgplot data=example;
reg x=year y=percent /group=treatment;
yaxis values=(0 to .5 by .1);
format percent percent5.;
run;

If you have a variable in the data set that has the Pvalue that is associated with the Treatment that can be added a couple of ways.

View solution in original post

5 REPLIES 5
ballardw
Super User

What you show is pretty clearly not a data set. So show what the DATASET looks like.

It may not hurt to mention trend of what. You show Yes/No as text combining a count and a percentage. So do you want to show a trend of Yes or No? Of the count or the percentage.

 

An example of what a data set to graph should look like and how to plot that with Treatment as a group variable.

data example;
  input treatment $ year percent;
datalines;
a  2000  .15
a  2001  .16
a  2002  .18
a  2003  .117
b  2000  .25
b  2001  .28
b  2002  .26
b  2003  .27
;

proc sgplot data=example;
   series x=year y=percent /group=treatment;
   yaxis values=(0 to .5 by .1);
   format percent percent5.;
run;
/* or fit a line through the points but not connect*/ proc sgplot data=example;
reg x=year y=percent /group=treatment;
yaxis values=(0 to .5 by .1);
format percent percent5.;
run;

If you have a variable in the data set that has the Pvalue that is associated with the Treatment that can be added a couple of ways.

ChuksManuel
Pyrite | Level 9

Hi,

This is what i have from Excel

 2000 2002 2004 2006 
Kind of treatmentYes, n (%) No, n (%)P-value Yes, n (%)  No, n (%)P-valueYes, n (%)No, n (%)P-valueYes, n (%)No, n (%)P-value
A633(6.5)9,177(93.5) 591(6.2)8,599(93.8) 691(6.2)10,428(93.8) 710  (6.5)10,178  (93.5) 
B848(8.7)8,951(91.3) 745(8.1)8,411(91.9) 901(8.1)10,184(91.9) 886  (8.2)9,983  (91.8) 
C150(1.5)9,674(98.5) 124(1.4)9,045(98.6) 177(1.6) 10,945(98.4) 172  (1.6) 10,721  (98.4) 
D111(1.1)9,700(98.9) 112(1.2)9,045(98.8) 143(1.3)10,964(98.7) 183  (1.7)10,702 (98.3) 
D523(5.3)9,295 (94.7) 541(5.9)8,617(94.1) 852(7.7)10,251(92.3) 920 (8.5) 9,967 (91.5) 
E219(2.2)9555(97.8) 237(2.6)8,870(97.4) 363(3.3)10,681(96.7) 327 (3.0) 10,502 (97) 
F152(1.6)9,642(98.4) 129(1.4)9,009(98.6) 173(1.6)10,898(98.4) 195(1.8) 10,652(98.2) 
G438(4.5)9,380(95.5) 422(4.6)8,748(95.4) 563(5.1)10,552(94.9) 571 (5.2)10,317 (94.8) 
H2,987(30.5)6,821(69.5) 2,808(30.7)6,352(69.3) 3,593(32.4)7,508(67.6) 3,700 (34)7,170 (66) 
PaigeMiller
Diamond | Level 26

We can't work from your Excel screen captures. You need to import the Excel file into SAS, and then show us it in SAS following these instructions, which will create SAS data step code that you can paste into your reply.

--
Paige Miller
ChuksManuel
Pyrite | Level 9

Thanks for the response. The Gplot can't plot multiple graphs on the same paper. I am trying to plot a graph of prevalence (yeses/Yes + No) of treatments across 4 years and for them to be on the same graph. Tried proc GREPLAY and it worked. Thanks for the contribution.

StatDave
SAS Super FREQ

Create a SAS data set with variables TRT, YEAR, NYES, and N and one observation for each TRT-YEAR combination. The NYES variable should contain the number of Yes responses and the N variable should contain the overall number in each TRT-YEAR combination. With that data set, you can then fit the following model that allows for the linear YEAR effect to vary for the treatments. The EFFECTPLOT statement draws the graph. In the results, the test of YEAR in the Type 3 table tells you if there is an overall linear YEAR effect and the test of the interaction tells you if there are any differences in the YEAR effect across the treatments.

PROC LOGISTIC;
class trt / param=glm; 
model nyes/n=trt|year;
effectplot slicefit(x=year sliceby=trt);
run;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 1466 views
  • 4 likes
  • 4 in conversation