I have the following dataset:
data have;
input dv1 dv2 dv3 dv4;
datalines;
1 0 1 0
0 0 1 -1
1 -1 0 0
0 1 1 1
0 0 1 -1
1 1 0 0
0 0 0 0
1 0 1 1
0 0 1 1
1 1 1 0
1 0 0 0
run;Using PROC MEANS I want to know the following frequencies:
dv2>0
dv2<0
dv4>0
dv4<0
dv2= 0 when dv1= 1
dv4= 0 when dv3= 1
How can I get them?
Much thanks again.
Regards.
@d6k5d3 wrote:
I have the following dataset:
data have; input dv1 dv2 dv3 dv4; datalines; 1 0 1 0 0 0 1 -1 1 -1 0 0 0 1 1 1 0 0 1 -1 1 1 0 0 0 0 0 0 1 0 1 1 0 0 1 1 1 1 1 0 1 0 0 0 run;Using PROC MEANS I want to know the following frequencies:
dv2>0
dv2<0
dv4>0
dv4<0
dv2= 0 when dv1= 1
dv4= 0 when dv3= 1
How can I get them?
It has to be PROC MEANS? You can't use a more appropriate tool like PROC FREQ? In PROC FREQ, the answer is easy. Why make extra work by forcing a tool like PROC MEANS to do something that it wasn't designed to do?????
Please see Maxim 14
Hi @d6k5d3,
Try this:
proc format;
value sign
low-<0 = '<0'
0 = ' 0'
0<-high = '>0';
run;
proc means data=have noprint;
format dv2 dv4 sign.;
class dv4 dv2 dv1 dv3;
types dv4 dv2 dv2*dv1 dv4*dv3;
output out=want;
run;
proc print data=want noobs;
run;
The output contains the requested counts (highlighted below):
dv4 dv2 dv1 dv3 _TYPE_ _FREQ_ . <0 . . 4 1 . 0 . . 4 7 . >0 . . 4 3 . <0 1 . 6 1 . 0 0 . 6 4 . 0 1 . 6 3 . >0 0 . 6 1 . >0 1 . 6 2 <0 . . . 8 2 0 . . . 8 6 >0 . . . 8 3 <0 . . 1 9 2 0 . . 0 9 4 0 . . 1 9 2 >0 . . 1 9 3
Nearly 200 sessions are now available on demand in the Innovate Hub.
Watch Now →SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.