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

I'm analyzing weighted survey data using PROC SURVEYFREQ. Column percentages are automatically calculated using a denominator that includes the weighted frequency of BOTH domain / flag_1 = 1 and domain / flag_1 = 0 (i.e., 53649500) (See pic). So the column percentage is 2.7866% (i.e., 1494991 / 53649500 = 2.7866%).

Screen Shot 2022-06-19 at 12.37.14 PM.png

How can I confine the calculation of column percentages to a given domain, so that the denominator is the weighted frequency of domain = 1 (i.e., 2071466)?

 

My desired column percentage calculation would be:

1494991 / 2071466 = 72.171%

 

Here's my syntax:

proc surveyfreq data=&dataset nomcar;
 	stratum sdmvstra;
 	cluster sdmvpsu;
 	weight &weight;
	
 	/* DOMAIN: used instead of the WHERE or BY statement to provide analyses of subgroups.  */
	/* The DOMAIN statement is not available with the SURVEYFREQ procedure.  */
	/* Use the DOMAIN variable in the TABLES statement instead */
 	
 	TABLE
/* 	NHANES variables */
		flag_1*
		(
 		ever_used
		cann_use_status	
		cann_use_status2
		monthly_yr

/* 		time_since_monthly_use */
/* 		time_since_monthly_use_unit */
		times_month
		joints_pipes_day
/* 		last_used */
/* 		last_use_unit */
			
/* 		Calculated variables */
/* 		mos_since_last_use */
/* 		yrs_since_last_use */
/* 		mos_since_monthly_use */
/* 		yrs_since_monthly_use */
 		)
 		/ cl col chisq cellchi2 relrisk;
/*  	*year/ cl col chisq cellchi2 relrisk; */
 		
 	FORMAT 
/* 		NHANES variables */
 		ever_told_mi 			yes_no_fmt.
 		ever_used				ever_usedfmt.
 		cann_use_status			cann_use_statusfmt.
 		cann_use_status2		cann_use_status2fmt.
		
		monthly_yr				monthly_yrfmt.
		
		times_month				times_monthfmt.
		joints_pipes_day		joints_pipes_dayfmt.
		
		year 					yearfmt.
		
/* 		Calculated variables */
/* 		mos_since_last_use	*/
/* 		yrs_since_last_use */
/* 		mos_since_monthly_use	mos_since_monthly_usefmt.	 */
/* 		yrs_since_monthly_use */	
		;
run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Have you tried including the ROW percentages in the output?

View solution in original post

1 REPLY 1
ballardw
Super User

Have you tried including the ROW percentages in the output?

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 2504 views
  • 1 like
  • 2 in conversation