BookmarkSubscribeRSS Feed
Ivy
Quartz | Level 8 Ivy
Quartz | Level 8

Dear all,

 

I would like to calculate mutiple percentage by treatment and put it to one table . Is there any efficeint way for this ?

 

proc freq data = t ;

tables treatment *( d1  d2  d3  ................................ d100) ;

run;

 

With the following output table :

 

treatment       disease          count   percentage 

 

1                   d1

                     d2

                     d3

                     .......

2                    

                     d1

                     d2

                     d3

                 ..........

 

4

 

 

Thank you,

Ivy 

 

 

11 REPLIES 11
Reeza
Super User

Transpose your data and use proc freq. 

 

Ivy
Quartz | Level 8 Ivy
Quartz | Level 8
Thank you, I do not think that works .
Reeza
Super User

Yes it does.

Why do you think it won't work? In fact, I think it was also suggested yesterday when you were looking for the maximum value.

Ivy
Quartz | Level 8 Ivy
Quartz | Level 8
Transpose worked for yesterday data, but not today's freq. The following is the codes I used, I am not sure whether this is the way you suggested . Thank you.

proc transpose data = ads out= ads_t;
by index_year ;
var COPD Chronic_kidney_disease
Congestive_heart_failure Coronary_Heart_Disease Dementia Diabetes HIV_AIDS Hemiplegia
Infectious_hepatitis Peripheral_vascular_disease Rheumatoid_arthritis Stroke Ulcer_disease
Venous_thromboembolism Alcoholic_liver_disease ;
run;
Ivy
Quartz | Level 8 Ivy
Quartz | Level 8
I would like to compare the different diseases percentage at different year. Thank you.
Reeza
Super User

The word year doesn't appear in your initial post...

Please post sample data and sample expected output. You can make fake data for 5 or 10 d's rather than the full 100.  

Ivy
Quartz | Level 8 Ivy
Quartz | Level 8

Thank you, Reeza.

Sample data:

treatment id d1 d2 d3
a 1 0 1 0
a 2 1 0 0
a 3 1 0 1
a 4 0 1 0
b 1 0 0 0
b 2 1 0 0
b 3 0 1 1
b 4 1 0 0

Output :

Treatment_a     Treatment_b     P-value 
d1 (percent)      

d2

d3

 

 

Reeza
Super User

Because you've coded your data as binary, transpose and use proc means. Sum will provide count and mean will provide the percentage. 

 

 

Ivy
Quartz | Level 8 Ivy
Quartz | Level 8
Thank you, Reeza. I just realized I forgot to add P-value to the output. So maybe I use proc freq to loop the variables and combine the output together instead of doing the task in one step.
Reeza
Super User

I have no idea what you want anymore...good luck.

ballardw
Super User

What test will you be running to get a p-value?

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
  • 11 replies
  • 1311 views
  • 0 likes
  • 3 in conversation