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,
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.
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.
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.
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.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.