BookmarkSubscribeRSS Feed
Kels123
Quartz | Level 8

Hi! 

I have paired pre- and post- data variables that are on a scale of 1-5. I ran a simple paired proc ttest using this code:

 

proc ttest data=TRUST.fellow_2 sides=2 alpha=0.05 h0=0;

title "Paired sample t-test example";

paired pre_comfort_inquiry*post_comfort_inquiry;

   run;

 

This code helped to produce this paired profiles plot:

Kels123_0-1737696137854.png

 

I would like to modify the range of the y-axis to go from 1-5 instead of 2-5. 

(I would also like to modify the printed labels of the pre_comfort_inquiry and post_comfort_inquiry variables as well as the title, but these have work-arounds.)

 

Is there any way to modify the y-axis range within the proc ttest function? For example, I would love to be able to add a line like this:

YAXIS LABEL = 'Response' GRID VALUES = (1.0 TO 5.0 BY 0.5);

 

The best option I have read about was using proc sgplot, but I'm not sure how to do this to get the graphics output I want and then be able to modify it in the way that I want.

 

Any example code or guidance would be greatly appreciated! Thank you.

 

5 REPLIES 5
Ksharp
Super User

You could SGPLOT it ,no need PROC TTEST at all.

 

data have;
input subject Baseline month1;
cards;
23 4 4
26 3 1
36 3 1
39 4 1
41 4 3
42 1 3
46 1 1
49 1 1
51 1 1
55 2 4
56 2 1
57 4 1
73 2 1
83 2 1
84 1 1
85 3 2
89 1 1
96 2 1
101 2 3
112 2 1
117 4 1
120 2 1
124 2 1
;
run;

proc transpose data= have out=canplot prefix=y;
   by subject;
run;
proc sql;
create table want as
select *,ifn(_NAME_='Baseline',1,2) as g from canplot
outer union 
select 1 as x2,median(Baseline) as y2 from have   /*Baseline*/
outer union corr
select 2 as x2,median(month1) as y2 from have  /*month1*/
;quit;

title 'Change in Score';
proc sgplot data=want noautolegend noborder aspect=0.5;
styleattrs datacontrastcolors=(orange black) datalinepatterns=(solid dash);
  series x=g y=y1 / group=subject lineattrs=(color=orange thickness=8 pattern=solid) transparency=0.5;
  series x=x2 y=y2/lineattrs=(color=black thickness=8 pattern=dash);
  xaxis type=linear offsetmin=0.01 values=(0.5 1 2 2.5) valuesdisplay=(' ' 'Baseline' '1 month' ' ') display=(nolabel noline noticks);
  yaxis  LABEL = 'Response' GRID VALUES = (1.0 TO 5.0 BY 0.5) grid display=(noline noticks) valuesformat=best.;
run;

Ksharp_0-1737702049819.png

 

Kels123
Quartz | Level 8

Thank you so much! This is definitely getting me on the right track. I did notice, however, that the output is different. Initially, this is what the output looked like from proc ttest:

Kels123_0-1737755151799.png

 

Here is my code, which is essentially the code you provided but with dataset names and variable labels modified. I also changed "median" to "mean" in these lines:

select 1 as x2,mean(pre_comfort_inquiry) as y2 from TRUST.fellow_2   /*Pre*/

 

MY CODE:

proc sort data=TRUST.fellow_2; by record_ID; run;

proc transpose data=TRUST.fellow_2 out=canplot prefix=y;

by record_ID; 

where post_distress ne . ;

run;

proc sql;

create table want_inquiry as

select *,ifn(_NAME_='pre_comfort_inquiry',1,2) as g from canplot

outer union 

select 1 as x2,mean(pre_comfort_inquiry) as y2 from TRUST.fellow_2   /*Pre*/

outer union corr

select 2 as x2,mean(post_comfort_inquiry) as y2 from TRUST.fellow_2  /*Post*/

;quit;

title 'Change in Comfort Level Score for Trauma Inquiry';

proc sgplot data=want_inquiry noautolegend noborder aspect=0.5;

styleattrs datacontrastcolors=(orange black) datalinepatterns=(solid dash);

  series x=g y=y1 / group=record_ID lineattrs=(color=orange thickness=8 pattern=solid) transparency=0.5;

  series x=x2 y=y2/lineattrs=(color=black thickness=8 pattern=dash);

  xaxis type=linear offsetmin=0.01 values=(0.5 1 2 2.5) valuesdisplay=(' ' 'Pre-Training' 'Post-Training' ' ') display=(nolabel noline noticks);

  yaxis  LABEL = 'Response' GRID VALUES = (1.0 TO 5.0 BY 0.5) grid display=(noline noticks) valuesformat=best.;

run;

 

This is what the output looks like. Clearly something is a bit off because the lines are different, dip below 1 (there are no values below 1 that exist), and there is also an odd vertical line at the "post-training" point:

Kels123_1-1737755180921.png

I went through the code line by line to try to detect errors, but wondering if you can tell from the output what I might need to adjust?

 

In case you are wondering, if I don't change "median" to "mean" in those two coding lines, this is what the output looks like (not too different):

Kels123_2-1737755275839.png

 

Thanks again!

 

Ksharp
Super User

That would be better if you could post some data to test your code to address your problem.

 

 

data have;
input subject Baseline month1;
cards;
23 4 4
26 3 1
36 3 1
39 4 1
41 4 3
42 1 3
46 1 1
49 1 1
51 1 1
55 2 4
56 2 1
57 4 1
73 2 1
83 2 1
84 1 1
85 3 2
89 1 1
96 2 1
101 2 3
112 2 1
117 4 1
120 2 1
124 2 1
;
run;

proc transpose data= have out=canplot prefix=y;
   by subject;
run;
proc sql;
create table want as
select *,ifn(_NAME_='Baseline',1,2) as g from canplot
outer union 
select 1 as x2,mean(Baseline) as y2 from have   /*Baseline*/
outer union corr
select 2 as x2,mean(month1) as y2 from have  /*month1*/
;quit;

title 'Change in Score';
proc sgplot data=want ;
  series x=g y=y1 / group=subject lineattrs=(color=blue pattern=solid) transparency=0.5;
  series x=g y=y1 / group=subject lineattrs=(thickness=0)  y2axis;
  series x=x2 y=y2/lineattrs=(color=orange thickness=4 pattern=solid) name='mean' legendlabel='Mean';
  xaxis type=linear offsetmin=0.01 values=(0.5 1 2 2.5) valuesdisplay=(' ' 'Pre_comfort_inquiry' 'Post_comfort_inquiry' ' ') display=(nolabel);
  yaxis  LABEL = 'Response' GRID VALUES = (0 TO 5.0 BY 0.5) grid display=( noticks) valuesformat=best.;
  y2axis  display=( noticks nolabel) VALUES = (0 TO 5.0 BY 0.5) valuesformat=best.;
  keylegend 'mean' /position=bottom location=inside ;
run;

Ksharp_0-1737769230378.png

 

 

Kels123
Quartz | Level 8

Of course! Here is my data for the variable post_comfort_inquiry:

 

Id  pre_comfort_inquiry  post_comfort_inquiry

AH5528 4 4

AL6451 4 4

AS6403 5 5

AS7965 4 5

CB7099 3 3

CJ3713 2 4

CL8387 3 4

EG3035 2 3

ES6296 2 4

GT1089 4 5

HN1886 2 3

JC6920 4 4

KG1333 3 3

KG3315 4 4

LP2936 3 4

LR2526 4 5

MM5879 4 4

MP3640 3 4

MS4312 2 5

NA6176 4 4

ND4436 4 4

OM7859 3 4

PF2214 4 4

RJ8260 3 4

RM1809 2 4

SK8223 4 4

SN6295 4 4

TG0311 4 4

TK0180 5 4

 

Thank you so much for any guidance you can offer!

 

Ksharp
Super User
data have;
input Id  $ pre_comfort_inquiry  post_comfort_inquiry;
cards;
AH5528 4 4
AL6451 4 4
AS6403 5 5
AS7965 4 5
CB7099 3 3
CJ3713 2 4
CL8387 3 4
EG3035 2 3
ES6296 2 4
GT1089 4 5
HN1886 2 3
JC6920 4 4
KG1333 3 3
KG3315 4 4
LP2936 3 4
LR2526 4 5
MM5879 4 4
MP3640 3 4
MS4312 2 5
NA6176 4 4
ND4436 4 4
OM7859 3 4
PF2214 4 4
RJ8260 3 4
RM1809 2 4
SK8223 4 4
SN6295 4 4
TG0311 4 4
TK0180 5 4
;
run;

proc transpose data= have out=canplot prefix=y;
   by id;
run;
proc sql;
create table want as
select *,ifn(lowcase(_NAME_)='pre_comfort_inquiry',1,2) as g from canplot
outer union 
select 1 as x2,mean(pre_comfort_inquiry) as y2 from have   /*Baseline*/
outer union corr
select 2 as x2,mean(post_comfort_inquiry) as y2 from have  /*month1*/
;quit;

title 'Change in Score';
proc sgplot data=want ;
  series x=g y=y1 / group=id lineattrs=(color=blue pattern=solid) transparency=0.5;
  series x=g y=y1 / group=id lineattrs=(thickness=0)  y2axis;
  series x=x2 y=y2/lineattrs=(color=orange thickness=4 pattern=solid) name='mean' legendlabel='Mean';
  xaxis type=linear offsetmin=0.01 values=(0.5 1 2 2.5) valuesdisplay=(' ' 'Pre_comfort_inquiry' 'Post_comfort_inquiry' ' ') display=(nolabel);
  yaxis  LABEL = 'Response' GRID VALUES = (1 TO 5.0 BY 0.5) grid display=( noticks) ;
  y2axis  display=( noticks nolabel) VALUES = (1 TO 5.0 BY 0.5);
  keylegend 'mean' /position=bottom location=inside ;
run;

Ksharp_0-1737788820446.png

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 966 views
  • 0 likes
  • 2 in conversation