DATA Step, Macro, Functions and more

Proc Freq table

Reply
Contributor
Posts: 58

Proc Freq table

Hello,

 

I've a dataset with 10 variables and each takes only 0 or 1 (No/Yes). I want to compare the freq of 'yes' among variables to a specific variables called VLU (also yes/no), shown in the picture.

 

Thanks in advance!

 

Capture.PNG

Super User
Posts: 6,786

Re: Proc Freq table

Posted in reply to Sujithpeta

A couple of suggestions ...

 

First, it's easier to use PROC TABULATE to get these results.

 

Second, I imagine you don't need the frequency of YES for VARIABLE1 through VARIABLE9. Rather, you could use the average value.  A side benefit would be that you can condense the table into one row for each of the 9 variables.  So, consider this:

 

proc tabulate data=have;

class VLU;

var variable1-variable9;

tables VLU * mean=' ', variable1-variable9;

run;

 

There are lots of ways to improve the table appearance, but see if this gets you started in the right direction.  You also might need to add a format for VLU, using a format that prints 1 as "Yes" and 0 as "No".

Super User
Posts: 13,583

Re: Proc Freq table

Posted in reply to Sujithpeta

One way to get started:

proc tabulate data=have;
   class vlu;
   var variable1-variable9;
   table variable1-variable*sum='',
         vlu
   ;
run;

options affecting appearance such as a format for VLU to display Yes/NO instead of 1/0 and such to make this prettier.

 

Labels for variables also.

 

Proc freq doesn't let you combine that many variables into a single result, Procs Tabulate and Report would.

Contributor
Posts: 58

Re: Proc Freq table

How should I change the code if each variable has different name and not in a sequence to write as Variable1-Variable?

 

Thanks

Super User
Posts: 6,786

Re: Proc Freq table

[ Edited ]
Posted in reply to Sujithpeta

You can replace variable1-variable9 with a list:

 

variable1 variable2 variable3 ..... variable9

 

Depending on where it appears  in PROC TABULATE, you may need to enclose the list in parentheses.

 

Also, I think the best table structure would be a combination of what I posted and what @ballardw posted:

 

tables variable1-variable9, VLU * mean=' ';

 

You can experiment with using SUM= or MEAN=, to see which you prefer.

Super User
Posts: 13,583

Re: Proc Freq table

Posted in reply to Astounding

@Astounding wrote:

You can replace variable1-variable9 with a list:

 

variable1 variable2 variable3 ..... variable9

 

Depending on where it appears  in PROC TABULATE, you may need to enclose the list in parentheses.

 

Also, I think the best table structure would be a combination of what I posted and what @ballardw posted:

 

tables variable1-variable9, VLU * mean=' ';

 

You can experiment with using SUM= or MEAN=, to see which you prefer.


The mean of a 0/1 coded response as @Astounding suggests will give the percentage of 1's. In which case you might want to us

mean*f=percent8.2 or similar. The *f= says to use the format following the = as the format for the resulting statistic.

The sum I suggested give the count of 1's. So use of sum*f=6. would suppress the default decimal portion and assume 6 characters as the longest result.

Ask a Question
Discussion stats
  • 5 replies
  • 72 views
  • 0 likes
  • 3 in conversation