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 FREQ or any better PROC 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.

2 REPLIES 2
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13
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
;

proc freq data=have;
	tables dv2 dv4 dv2*dv1 dv4*dv3;
run;

The FREQ Procedure

The Freq Procedure

Table dv2

One-Way Frequencies

 
dv2 Frequency Percent Cumulative
Frequency
Cumulative
Percent
-1 1 9.09 1 9.09
0 7 63.64 8 72.73
1 3 27.27 11 100.00

Table dv4

One-Way Frequencies

 
dv4 Frequency Percent Cumulative
Frequency
Cumulative
Percent
-1 2 18.18 2 18.18
0 6 54.55 8 72.73
1 3 27.27 11 100.00

Table dv2 * dv1

Cross-Tabular Freq Table

 
Frequency
Percent
Row Pct
Col Pct
Table of dv2 by dv1
dv2 dv1
0 1 Total
-1
0
0.00
0.00
0.00
1
9.09
100.00
16.67
1
9.09
 
 
0
4
36.36
57.14
80.00
3
27.27
42.86
50.00
7
63.64
 
 
1
1
9.09
33.33
20.00
2
18.18
66.67
33.33
3
27.27
 
 
Total
5
45.45
6
54.55
11
100.00

Table dv4 * dv3

Cross-Tabular Freq Table

 
Frequency
Percent
Row Pct
Col Pct
Table of dv4 by dv3
dv4 dv3
0 1 Total
-1
0
0.00
0.00
0.00
2
18.18
100.00
28.57
2
18.18
 
 
0
4
36.36
66.67
100.00
2
18.18
33.33
28.57
6
54.55
 
 
1
0
0.00
0.00
0.00
3
27.27
100.00
42.86
3
27.27
 
 
Total
4
36.36
7
63.64
11
100.00
ballardw
Super User

@d6k5d3 wrote:

I have the following dataset:

 

Using PROC FREQ or any better PROC 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.


What do you want done about the dv2 and dv4 = 0? Do need the percents or just the counts of <0 and > 0?

One common approach to examining groups of a variable's values is to use a custom format. Such as

proc format library=work;
value notzero
low -<0 ='<0'
0< -high='>0'
;


proc freq data=have;
   tables dv2 dv4 ;
   format dv2 dv4 notzero.;
run;

However a format would be applied to all use of the variables in single proc freq so to get the other bits you would need a separate call to proc freq.

 

And if you need a data set there are other considerations involved.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 2 replies
  • 1450 views
  • 2 likes
  • 3 in conversation