BookmarkSubscribeRSS Feed
Sujithpeta
Quartz | Level 8

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

5 REPLIES 5
Astounding
PROC Star

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".

ballardw
Super User

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.

Sujithpeta
Quartz | Level 8

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

 

Thanks

Astounding
PROC Star

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.

ballardw
Super User

@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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 781 views
  • 0 likes
  • 3 in conversation