BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
ybz12003
Rhodochrosite | Level 12

Hello,

I have a dataset shown below. I would like to get mean/median/IQR/sum/sum_percent in each "Lab/Pham/Diag"  group, excluding the missing values.  Please let me know how to approach, thanks.

data Bill;  
	length caseid $10 Lab 3 Pham 4 Diag 4; 
	infile datalines delimiter=','; 
	input Caseid Lab Pham Diag;  
	datalines;                     
	EC1R00002,200,6000,5500,
	AC1R00012,100, , 7000,
	EC1R00013,50,3800, ,
	BH1U00185, ,4600,1500,
	EN1R01252,700,9000,2900,
	CY1K01251, ,500, , 
	BH1U99185,900,5600,8500,
	OP1R00252,360,9900,8900,
	PCHK01401,770,, , 
;   
1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

I don't know what you mean by "sum_percent"

 

Otherwise, this gets the job done:

 

proc means data=bill stackodsoutput mean median p25 p75 sum;
    ods output summary=summary;
    var lab pham diag;
run;

 

 

You will have to compute the IQR from the p75 and p25 values.

--
Paige Miller

View solution in original post

7 REPLIES 7
PaigeMiller
Diamond | Level 26

I don't know what you mean by "sum_percent"

 

Otherwise, this gets the job done:

 

proc means data=bill stackodsoutput mean median p25 p75 sum;
    ods output summary=summary;
    var lab pham diag;
run;

 

 

You will have to compute the IQR from the p75 and p25 values.

--
Paige Miller
ybz12003
Rhodochrosite | Level 12
Lab (Sum_%)= Lab_sum / [Sum(Lab+Pha+Dia)]
PaigeMiller
Diamond | Level 26

@ybz12003 wrote:
Lab (Sum_%)= Lab_sum / [Sum(Lab+Pha+Dia)]

I'm not sure what this means. From the data you posted, the sums are

 

LAB 3080

PHAM 39400

Diag 34300

 

So are you asking for code to compute 3080/(3080+39400+34300) ??

--
Paige Miller
ybz12003
Rhodochrosite | Level 12
Yes
PaigeMiller
Diamond | Level 26
proc means data=bill stackodsoutput mean median p25 p75 sum;
   ods output summary=summary;
   var lab pham diag;
run;
proc sql;
    create table want as select
    *,
    sum / sum(sum) as sum_pct
    from summary;
quit;
--
Paige Miller
ybz12003
Rhodochrosite | Level 12

Is it a way to format the number to one digit after the decimal? 

PaigeMiller
Diamond | Level 26

Yes, assign the proper format to the variable.

--
Paige Miller

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 7 replies
  • 554 views
  • 1 like
  • 2 in conversation