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!
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
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
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.
Ready to level-up your skills? Choose your own adventure.