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

Dear all, 

I am new to SAS. First of all, here is a sample of the data: 

PairsInstrument typeIssuer name (same)YTM 
1AX3,459742 
1BX2.8651 
2AY3,464001 
2BY2,2493 
3AZ2,6682 
3BZ4,623 
4AT2,752 
4BT3,86234 

 

The idea is to do a descriptive statistics to compare A and B.  A and B must be from the same issuer. To do so, I formed pairs. 
I couldn't  find a command that would give the mean difference between the YTMs of A and B as follows : YTMb A (i)-YTM B (i) where i is the pair. 


Logically, I would use the proc ttest but the difference in YTM must be only from the same pair. 

 

In the result, the diff(A-B) should be only based on a two by two difference from the same pair. 

I hope I am clear. 

Thank you for your help. 

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hello @Emna1 and welcome to the SAS Support Communities!

 


@Emna1 wrote:

Logically, I would use the proc ttest ...


This is a great idea. The PAIRED statement of the TTEST procedure requires the YTM values of A and B to be in separate variables so that each observation of the input dataset represents one pair. You can use PROC TRANSPOSE to reshape the data in this way -- assuming that you already have a SAS dataset (like dataset HAVE in the code below) containing the data shown in your table.

/* Create sample data for demonstration */

data have;
input pair instrument_type $ issuer_name $ YTM :numx.;
cards;
1 A X 3,459742
1 B X 2,8651
2 A Y 3,464001
2 B Y 2,2493
3 A Z 2,6682
3 B Z 4,623
4 A T 2,752
4 B T 3,86234
;

/* Reshape the data for PROC TTEST */

proc transpose data=have out=want;
by pair issuer_name; /* alternatively: by issuer_name notsorted; */
id instrument_type;
var YTM;
run;

/* Use PROC TTEST to compute descriptive statistics for A-B */

proc ttest data=want;
paired A*B;
run;

 

View solution in original post

2 REPLIES 2
FreelanceReinh
Jade | Level 19

Hello @Emna1 and welcome to the SAS Support Communities!

 


@Emna1 wrote:

Logically, I would use the proc ttest ...


This is a great idea. The PAIRED statement of the TTEST procedure requires the YTM values of A and B to be in separate variables so that each observation of the input dataset represents one pair. You can use PROC TRANSPOSE to reshape the data in this way -- assuming that you already have a SAS dataset (like dataset HAVE in the code below) containing the data shown in your table.

/* Create sample data for demonstration */

data have;
input pair instrument_type $ issuer_name $ YTM :numx.;
cards;
1 A X 3,459742
1 B X 2,8651
2 A Y 3,464001
2 B Y 2,2493
3 A Z 2,6682
3 B Z 4,623
4 A T 2,752
4 B T 3,86234
;

/* Reshape the data for PROC TTEST */

proc transpose data=have out=want;
by pair issuer_name; /* alternatively: by issuer_name notsorted; */
id instrument_type;
var YTM;
run;

/* Use PROC TTEST to compute descriptive statistics for A-B */

proc ttest data=want;
paired A*B;
run;

 

Emna1
Calcite | Level 5

This is exactly what I asked for. Thank you very much for your help ! 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 2 replies
  • 407 views
  • 1 like
  • 2 in conversation