Desktop productivity for business analysts and programmers

Frequencies and percentages in multiple columns with same variable

Reply
New Contributor
Posts: 2

Frequencies and percentages in multiple columns with same variable

Hello people

 

I'm new with SAS and have just started using Enterprise Guide. I've got a bit stuck with the statistics and I hope you can help me.

 

A segment of my sheet looks something like this:

 

id           graft_comp1                   graft_comp2           graft_comp3

1            Ascites                           Rejection
2            Hypoalbuminemia           Hypoalbuminemia           
3            Hypoalbuminemia           Ascites                   Ascites
4            Rejection                        Rejection
5            Ascites

 

I would like to get the frequencies and percentages of each complication (after surgery) from all the columns. I have tried with this:

proc freq data=komplib.cdmerged;
tables graft_comp1 graft_comp2 graft_comp3 / nocum ;
run;

 

But this way I get the data in tree different tables.

Is there any way I can get the results as a sum of all data in the columns collectively?

 

Plese helt me. Smiley Happy

Thomas






 

Super User
Posts: 5,369

Re: Frequencies and percentages in multiple columns with same variable

Not without jumping through some sort of hoop.  The easiest hoop to jump through is probably this one:

 

data temp;

set have;

if graft_comp1 > ' ' then do;

   complication = graft_comp1;

   output;

end;

if graft_comp2 > ' ' then do;

   complication = graft_comp2;

   output;

end;

if graft_comp3 > ' ' then do;

   complication = graft_comp3;

   output;

end;

run;

 

proc freq data=temp;

tables complication / nocum;

run;

 

If you have a large number of variables, not just 3, you don't have to spell out the logic for all of them.  Instead, you could create an array in the DATA step, and process each variable in the array.

New Contributor
Posts: 2

Re: Frequencies and percentages in multiple columns with same variable

Thank you very much for your reply.

I will try if I can get it to work.

Should I just copy past your codes or is there any changes I need to make? I am very new with SAS so I might need some very specific directions.

 

Thomas

Super User
Posts: 5,369

Re: Frequencies and percentages in multiple columns with same variable

There is just one line that needs to change:

 

set have;

 

You have to plug in the name of your data set here.

PROC Star
Posts: 1,146

Re: Frequencies and percentages in multiple columns with same variable

Another option is to use the Data > Transpose task in EG. Make sure your data is sorted by "id", and then put "id" in the "Group Analysis By" variable and the three "comp" variables in "Transpose Variables". Then you'll just need a quick query to eliminate the blank cells.

 

Tom

Ask a Question
Discussion stats
  • 4 replies
  • 157 views
  • 0 likes
  • 3 in conversation