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

Hi all, 

 

I'm a SAS newbie! I have a very large dataset and it looks similar to this:

 

var1       var2         var3          var4        var5  

10384     35            1                5            1

10383     56            2                3            2

10567     76            1                4            5

 

Var5 indicates the number of rows with the same information so it really is this:

var1       var2         var3          var4               

10384     35            1                5            

10383     56            2                3           

10383     56            2                3            

10567     76            1                4            

10567     76            1                4            

10567     76            1                4            

10567     76            1                4            

10567     76            1                4    

        

How do I find the frequency for var1, var2, var3, and var4 without expanding the dataset? 

 

    

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
data have;
input var1       var2         var3          var4        var5  ;
cards;
10384     35            1                5            1
10383     56            2                3            2
10567     76            1                4            5
;
run;
proc freq data=have noprint;
table var1/out=want1 ;
table var2/out=want2 ;
weight var5;
run;

View solution in original post

4 REPLIES 4
novinosrin
Tourmaline | Level 20

A simple transpose gives 

 

proc transpose data=have out=w;
by var5;
var var1-var4;
run;

proc print noobs;run;

gives  

 

1 var1 10384
1 var2 35
1 var3 1
1 var4 5
2 var1 10383
2 var2 56
2 var3 2
2 var4 3
5 var1 10567
5 var2 76
5 var3 1
5 var4 4

 

I'm not clear with your expected output yet. Do you want the frequencies of each value of var1 -- var4 or number of records in var1,var2  and var4?

If I were to assume it is frequencies of each value of var1-var4, 

 


proc sql;
create table want as
select col1, sum(var5) as freq
from w
group by col1;
quit;

gives 

 

COL1 freq

1 6
2 2
3 2
4 5
5 1
35 1
56 2
76 5
10383 2
10384 1
10567 5

Ksharp
Super User
data have;
input var1       var2         var3          var4        var5  ;
cards;
10384     35            1                5            1
10383     56            2                3            2
10567     76            1                4            5
;
run;
proc freq data=have noprint;
table var1/out=want1 ;
table var2/out=want2 ;
weight var5;
run;
axeloop
Calcite | Level 5

I see that I needed to use "weight". It worked perfectly! Thanks.

VDD
Ammonite | Level 13 VDD
Ammonite | Level 13
data have;
infile cards missover;
input var1       var2         var3          var4;
cards;               
10384     35            1                5            
10383     56            2                3           
10383     56            2                3            
10567     76            1                4            
10567     76            1                4            
10567     76            1                4            
10567     76            1                4            
10567     76            1                4   
run;
proc freq data=have;
	tables var1 var2 var3 var4 / out=want;
run;
proc freq data=have;
	tables var1*var2 /out=want2;
run;
 

Depends on what you really want

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
  • 4 replies
  • 1188 views
  • 0 likes
  • 4 in conversation