Hi Guys Good Morning
I want to output F and M alternatively sex in class dataset using proc report compute block
proc report data=sashelp.class;
columns Name Sex ;
define Name ;
define sex
computer after Sex;
IF Sex='F'
output;
IF Sex='M'
output;
end comp;
run;
How should that report look in the end?
The usual answer: PROC REPORT is the wrong tool. Use the DATA step to manipulate data.
Hi:
The first consideration is that PROC REPORT does NOT support the OUTPUT statement. OUTPUT is a statement that can only be used in a DATA step program. If you want to see Males and Females separately, either use BY group processing or use the PROC REPORT usage of GROUP in the DEFINE statement.
Here are some examples using SASHELP.CLASS and PROC REPORT:
** Example 1;
proc report data=sashelp.class;
title '1) Using ORDER variables for detail report';
column sex name age height weight;
define sex / order;
define name / display;
define age / display;
define height/ mean f=6.2;
define weight / mean f=6.2;
break after sex / summarize;
compute after sex;
line ' ';
endcomp;
run;
** Example 2;
proc report data=sashelp.class;
title '2) Using GROUP variables for summary report';
column sex name age height weight;
define sex / group;
define age / group;
define height/ mean f=6.2;
define weight / mean f=6.2;
break after sex / summarize;
compute after sex;
line ' ';
endcomp;
run;
** Example 3;
proc report data=sashelp.class;
title '3) Using ORDER variable and PAGE option for detail report';
column sex name age height weight;
define sex / order page;
define name / display;
define age / display;
define height/ mean f=6.2;
define weight / mean f=6.2;
break after sex / summarize;
compute after sex;
line ' ';
endcomp;
run;
** Example 4;
proc sort data=sashelp.class out=class;
by sex name;
run;
proc report data=class;
title '4) Using BY GROUP processing for detail report';
column sex name age height weight;
by sex;
define name / order;
define age / display;
define height/ mean f=6.2;
define weight / mean f=6.2;
rbreak after / summarize;
run;
Hope this helps,
Cynthia
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.