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

Question:

After I run Proc Print data=A2, the output does not seem to be right.

Variable

N

Mean

Std Dev

Minimum

Maximum

ID

DBP1

DBP2

DropInDBP

47

47

47

47

173.3617021

64.6808511

63.9148936

0.7659574

85.6942050

7.1539177

7.2466778

2.3051244

101.0000000

48.0000000

46.0000000

-4.0000000

403.0000000

82.0000000

82.0000000

8.0000000

 


 

 

Obs

_TYPE_

_FREQ_

AveDBP1

AveDBP2

SDDBP1

SDDBP2

1

0

47

173.362

64.6809

85.6942

7.15392

 

As you can see, the AveDBP1 is in fact the average of ID,

The AveDBP2 is in fact the average of DBP1  and so on.

 

It seems that the calculation happens for the wrong variable. Where am I going wrong?

 

Thank you.

Libname HW 'C:\Desktop';
Data HW8;
Set HW.HW8;
DropInDBP = DBP1-DBP2;
run;
Proc univariate normal;
	var DBP1 DBP2 DropInDBP;
	histogram / normal;
run;
Proc ttest h0=66;
	var DBP1;
run;
Proc ttest h0=62;
	var DBP2;
run;
Proc ttest;
	paired DBP1*DBP2;
run;
Proc Means;
Output out=A2 mean = AveDBP1 AveDBP2 std = SDDBP1 SDDBP2;
run;
Proc print data=A2;
run;
1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

It works fine for me.

data CLASS;
 set SASHELP.CLASS;
run;
proc univariate normal;
  var WEIGHT HEIGHT;
  histogram / normal;
run;
proc ttest h0=66;
  var WEIGHT;
run;
proc ttest h0=62;
  var HEIGHT;
run;
proc ttest;
  paired WEIGHT*HEIGHT;
run;
proc means ;
  var WEIGHT HEIGHT;
  output out=A2 mean = AVEDBP1 AVEDBP2 std = SDDBP1 SDDBP2;
run;
proc print data=A2;
run;

The only explanation I can offer is your VAR statement is not in order.

View solution in original post

6 REPLIES 6
ChrisNZ
Tourmaline | Level 20

What happens when you add a  var statement to proc means?

sachin05t
Calcite | Level 5

I had tied that. I get the same result.

ChrisNZ
Tourmaline | Level 20

It works fine for me.

data CLASS;
 set SASHELP.CLASS;
run;
proc univariate normal;
  var WEIGHT HEIGHT;
  histogram / normal;
run;
proc ttest h0=66;
  var WEIGHT;
run;
proc ttest h0=62;
  var HEIGHT;
run;
proc ttest;
  paired WEIGHT*HEIGHT;
run;
proc means ;
  var WEIGHT HEIGHT;
  output out=A2 mean = AVEDBP1 AVEDBP2 std = SDDBP1 SDDBP2;
run;
proc print data=A2;
run;

The only explanation I can offer is your VAR statement is not in order.

sachin05t
Calcite | Level 5

It worked !

ChrisNZ
Tourmaline | Level 20

Always code all the options. Don't omit data= or the var statement.

Anything implicit will save you seconds typing and waste much more later on, like it did here.

Reeza
Super User

1. You didn't specify a VAR statement. So SAS calculates statistics for all numeric variables. 

2. You DID specify the name of the output variables....but because you didn't specify the VAR statement, SAS uses the order they appear in the data set, which doesn't appear to match the order of the output variables. 

 

You can use implicit naming but then you need to consistently use it. 

Or explicitly declare everything. 

 

 

proc means data=HW8;
output out=A2 mean= std= /autoname;
run;

 

 

I would very very strongly recommend you add a DATA= statement to all your PROC as well. Otherwise you're implicitly referencing your data set and as you can see, it is hard to know which data set would be used in the analysis. 

So, not only the PROC MEANS, but PROC TTEST, otherwise I guarantee you're going to have wrong results throughout. You may get results still, but they may not be what you expect and if you're just learning it's very very easy to miss it. In general, this is never good practice and after programming ten years I never do this. 

 

See the red sections below. 

 

 

Libname HW 'C:\Desktop';*I hope you're not writing to your desktop, it'll be a massive mess;
Data HW8;
Set HW.HW8;
DropInDBP = DBP1-DBP2;
run;
Proc univariate normal; * Which dataset is being used here?;
	var DBP1 DBP2 DropInDBP;
	histogram / normal;
run;
Proc ttest h0=66; *Which dataset is being used here?;
	var DBP1;
run;
Proc ttest h0=62;*which dataset is being used here?;
	var DBP2;
run;
Proc ttest;*which data set is being used here?;
	paired DBP1*DBP2;
run;
Proc Means Data=HW8; *easy to see this is using HW8 data with the DATA=;
Output out=A2 mean = AveDBP1 AveDBP2 std = SDDBP1 SDDBP2;
run;
Proc print data=A2;
run;

 


@sachin05t wrote:
 

Question:

After I run Proc Print data=A2, the output does not seem to be right.

Variable

N

Mean

Std Dev

Minimum

Maximum

ID

DBP1

DBP2

DropInDBP

47

47

47

47

173.3617021

64.6808511

63.9148936

0.7659574

85.6942050

7.1539177

7.2466778

2.3051244

101.0000000

48.0000000

46.0000000

-4.0000000

403.0000000

82.0000000

82.0000000

8.0000000

 


 

 

Obs

_TYPE_

_FREQ_

AveDBP1

AveDBP2

SDDBP1

SDDBP2

1

0

47

173.362

64.6809

85.6942

7.15392

 

As you can see, the AveDBP1 is in fact the average of ID,

The AveDBP2 is in fact the average of DBP1  and so on.

 

It seems that the calculation happens for the wrong variable. Where am I going wrong?

 

Thank you.

Libname HW 'C:\Desktop';
Data HW8;
Set HW.HW8;
DropInDBP = DBP1-DBP2;
run;
Proc univariate normal;
	var DBP1 DBP2 DropInDBP;
	histogram / normal;
run;
Proc ttest h0=66;
	var DBP1;
run;
Proc ttest h0=62;
	var DBP2;
run;
Proc ttest;
	paired DBP1*DBP2;
run;
Proc Means;
Output out=A2 mean = AveDBP1 AveDBP2 std = SDDBP1 SDDBP2;
run;
Proc print data=A2;
run;

 

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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
  • 6 replies
  • 1950 views
  • 0 likes
  • 3 in conversation