BookmarkSubscribeRSS Feed
d6k5d3
Pyrite | Level 9

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.

3 REPLIES 3
PaigeMiller
Diamond | Level 26

@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

https://communities.sas.com/t5/SAS-Communities-Library/Maxims-of-Maximally-Efficient-SAS-Programmers...

--
Paige Miller
d6k5d3
Pyrite | Level 9
Would you please tell me how I can do this using PROC FREQ? I didn't have the idea about using it. The only other way I could figure out was PROC SQL which for some reasons I cannot use.

Much thanks.
FreelanceReinh
Jade | Level 19

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