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

Hi all SAS Users,

In my code below, I need to use one more datastep to calculate the variable chl_y_c as below, I am wondering if there is any chance to merge the proc means and data step below together:

proc means data=_w.chl_yc_d noprint;
by gviidkey year;
var s_yc_d appday;
output out=chl_yc_d_ (keep=gviidkey year s_yc_y appdaysum where=(appdaysum >=12))
	mean=s_yc_y sum=SC APPDAYSUM;
run;

data chl_yc_final;
	set chl_yc_d_;
		chl_y_c=sqrt(max(4*s_yc_y, 0));
run;

Warmest regards,

Thank you for your help, have a fabulous and productive day! I am a novice today, but someday when I accumulate enough knowledge, I can help others in my capacity.
1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hi @Phil_NZ,

 

No, you can't do calculations like this within PROC MEANS. You could compute the summary statistics and do the calculation in a DATA step or (easier to code, but performance might be worse) in a PROC SQL step, though. But there's nothing wrong with using two separate steps for two different tasks.

 

You can make your PROC MEANS step a bit more efficient: Currently you compute the sums SC of the s_yc_d values per BY group, but you don't keep them in the output dataset. To compute only the sums of appday specify

sum(appday)=APPDAYSUM

in the OUTPUT statement.

View solution in original post

3 REPLIES 3
FreelanceReinh
Jade | Level 19

Hi @Phil_NZ,

 

No, you can't do calculations like this within PROC MEANS. You could compute the summary statistics and do the calculation in a DATA step or (easier to code, but performance might be worse) in a PROC SQL step, though. But there's nothing wrong with using two separate steps for two different tasks.

 

You can make your PROC MEANS step a bit more efficient: Currently you compute the sums SC of the s_yc_d values per BY group, but you don't keep them in the output dataset. To compute only the sums of appday specify

sum(appday)=APPDAYSUM

in the OUTPUT statement.

Kurt_Bremser
Super User

SAS procedures are pre-fabricated modules with a clearly defined (and limited) set of capabilities.

If MEANS does not have a specific statistic in its catalog (read the documentation), you have to calculate it yourself.

Reeza
Super User

Make sure to go through this example for PROC MEANS. There are many ways to control the output from PROC MEANS (not relevant to your question here) to get differently formatted output.

https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.5&docsetId=proc&docsetTarget=p17h6q7...

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 3 replies
  • 1453 views
  • 3 likes
  • 4 in conversation