I would like to create a table like this, where the sex variable is under the name variable, and the sex variable does not have a column to itself. I do not want to create separate tables or have any blank rows. The code below, using 'noprint' and adding the 'F' in column definition and 'M' in a line in 'compute' is going the right direction, but currently gives me an 'M' before the males and at the end of the report. I do not want the 'M' at the end of the report.
I'm using SAS EG 7.4.
So I want this (I've added the ... to make this post shorter):
Name | Age |
F | |
Alice | 13 |
Barbara | 13 |
… | |
M | |
Alfred | 14 |
Henry | 14 |
...
Code so far:
proc sort data=sashelp.class out=edu;
by sex name;
run;
proc report data=edu;
columns ('F' Sex Name ) Age;
define sex/group '' noprint;
define name/group;
define age/analysis;
compute after sex ;
line 'M' @1 ;
endcomp;
run;
Output from code above (with ... added):
F | |
Name | Age |
Alice | 13 |
Barbara | 13 |
… | |
M | |
Alfred | 14 |
Henry | 14 |
… | |
William | 15 |
M |
I'm using ODS excel then to output to an Excel file that I don't want to edit again.
Many thanks, and apologies if this has been asked before or I've left out essential details.
Very many thanks Cynthia, that worked.
I used this code from your paper successfully to suppress one value of a variable, but I don't understand how it worked.
...
if region = 'Canada' then reglg = 0;
else reglg = 1;
endcomp;
compute after region/ style=Header;
line brktxt $varying. reglg;
...
I understand setting the length to 0 will stop SAS from printing a blank line
But I don't understand how SAS knows to take the value of reglg as the length.
Many thanks again for your help.
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!
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.