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

So when I run a PROC MEANS on the following data:

data temp;
infile DATALINES dsd missover;
input ID DATE(month_num) Var1 Var1_Counter;
CARDS;
01, 1, ., .
01, 2, 3.5, 1
01, 3, ., 1
01, 4, 1.4, 2
01, 5, ., 2
02, 1, ., .
02, 2, 1.2, 1
02, 3, 1.4, 2
02, 4, 1.7, 3
02, 5, 5.1, 4
;
run;

Using:

PROC MEANS data = have ;
	var ID DATE Var1 Var1_counter;
	output out = want;
run;

My "N" column, which should be giving me 2 (since there are only 2 IDs) is actually giving me 10, for the total number of observations.

 

Does anyone know why? Additionally, how can my PROC means to also include _TYPE_ and _FREQ_ in the output table?

Thanks!

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Did you intend to use ID as a CLASS variable instead of an analysis variable?

data temp;
  input ID $ month_num Var1 Var1_Counter;
CARDS;
01 1 . .
01 2 3.5 1
01 3 . 1
01 4 1.4 2
01 5 . 2
02 1 . .
02 2 1.2 1
02 3 1.4 2
02 4 1.7 3
02 5 5.1 4
;

proc means data=temp;
  class id;
  output out=want;
run;

proc print data=want;
run;

You still won't get the value of N to be 2, unless one of your variables only has 2 non-missing values for one of the IDs.

But you will get output for ID=2 and another for ID=1. 

The MEANS Procedure

              N
ID          Obs    Variable         N            Mean         Std Dev         Minimum         Maximum
-----------------------------------------------------------------------------------------------------
01            5    month_num        5       3.0000000       1.5811388       1.0000000       5.0000000
                   Var1             2       2.4500000       1.4849242       1.4000000       3.5000000
                   Var1_Counter     4       1.5000000       0.5773503       1.0000000       2.0000000

02            5    month_num        5       3.0000000       1.5811388       1.0000000       5.0000000
                   Var1             4       2.3500000       1.8448125       1.2000000       5.1000000
                   Var1_Counter     4       2.5000000       1.2909944       1.0000000       4.0000000
-----------------------------------------------------------------------------------------------------
 
                                            month_                Var1_
Obs    ID    _TYPE_    _FREQ_    _STAT_      num        Var1     Counter

  1             0        10       N        10.0000    6.00000    8.00000
  2             0        10       MIN       1.0000    1.20000    1.00000
  3             0        10       MAX       5.0000    5.10000    4.00000
  4             0        10       MEAN      3.0000    2.38333    2.00000
  5             0        10       STD       1.4907    1.57660    1.06904
  6    01       1         5       N         5.0000    2.00000    4.00000
  7    01       1         5       MIN       1.0000    1.40000    1.00000
  8    01       1         5       MAX       5.0000    3.50000    2.00000
  9    01       1         5       MEAN      3.0000    2.45000    1.50000
 10    01       1         5       STD       1.5811    1.48492    0.57735
 11    02       1         5       N         5.0000    4.00000    4.00000
 12    02       1         5       MIN       1.0000    1.20000    1.00000
 13    02       1         5       MAX       5.0000    5.10000    4.00000
 14    02       1         5       MEAN      3.0000    2.35000    2.50000
 15    02       1         5       STD       1.5811    1.84481    1.29099

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

Did you intend to use ID as a CLASS variable instead of an analysis variable?

data temp;
  input ID $ month_num Var1 Var1_Counter;
CARDS;
01 1 . .
01 2 3.5 1
01 3 . 1
01 4 1.4 2
01 5 . 2
02 1 . .
02 2 1.2 1
02 3 1.4 2
02 4 1.7 3
02 5 5.1 4
;

proc means data=temp;
  class id;
  output out=want;
run;

proc print data=want;
run;

You still won't get the value of N to be 2, unless one of your variables only has 2 non-missing values for one of the IDs.

But you will get output for ID=2 and another for ID=1. 

The MEANS Procedure

              N
ID          Obs    Variable         N            Mean         Std Dev         Minimum         Maximum
-----------------------------------------------------------------------------------------------------
01            5    month_num        5       3.0000000       1.5811388       1.0000000       5.0000000
                   Var1             2       2.4500000       1.4849242       1.4000000       3.5000000
                   Var1_Counter     4       1.5000000       0.5773503       1.0000000       2.0000000

02            5    month_num        5       3.0000000       1.5811388       1.0000000       5.0000000
                   Var1             4       2.3500000       1.8448125       1.2000000       5.1000000
                   Var1_Counter     4       2.5000000       1.2909944       1.0000000       4.0000000
-----------------------------------------------------------------------------------------------------
 
                                            month_                Var1_
Obs    ID    _TYPE_    _FREQ_    _STAT_      num        Var1     Counter

  1             0        10       N        10.0000    6.00000    8.00000
  2             0        10       MIN       1.0000    1.20000    1.00000
  3             0        10       MAX       5.0000    5.10000    4.00000
  4             0        10       MEAN      3.0000    2.38333    2.00000
  5             0        10       STD       1.4907    1.57660    1.06904
  6    01       1         5       N         5.0000    2.00000    4.00000
  7    01       1         5       MIN       1.0000    1.40000    1.00000
  8    01       1         5       MAX       5.0000    3.50000    2.00000
  9    01       1         5       MEAN      3.0000    2.45000    1.50000
 10    01       1         5       STD       1.5811    1.48492    0.57735
 11    02       1         5       N         5.0000    4.00000    4.00000
 12    02       1         5       MIN       1.0000    1.20000    1.00000
 13    02       1         5       MAX       5.0000    5.10000    4.00000
 14    02       1         5       MEAN      3.0000    2.35000    2.50000
 15    02       1         5       STD       1.5811    1.84481    1.29099
UniversitySas
Quartz | Level 8
I see. Maybe I am misunderstanding what the output is supposed to say. I don't want my ID as a CLASS variable, so I think I made a mistake in my prior results. Thanks for the clarification!

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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