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

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):

NameAge
F 
Alice13
Barbara13
 
M 
Alfred14
Henry14

...

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 
NameAge
Alice13
Barbara13
 
M
Alfred14
Henry14
 
William15
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.

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ
Hi:
You need to use a COMPUTE block. See this paper: https://support.sas.com/resources/papers/proceedings17/SAS0431-2017.pdf particularly page 9, so you can see all the places you can write an extra line of text or line with a variable value using PROC REPORT.
Then the examples on pages 18-20 approx show the use of COMPUTE BEFORE to do what you want to do, I think.
Hope this helps,
Cynthia

View solution in original post

3 REPLIES 3
Cynthia_sas
SAS Super FREQ
Hi:
You need to use a COMPUTE block. See this paper: https://support.sas.com/resources/papers/proceedings17/SAS0431-2017.pdf particularly page 9, so you can see all the places you can write an extra line of text or line with a variable value using PROC REPORT.
Then the examples on pages 18-20 approx show the use of COMPUTE BEFORE to do what you want to do, I think.
Hope this helps,
Cynthia
PeterCulhane
Calcite | Level 5

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. 

Cynthia_sas
SAS Super FREQ
Hi:
Setting the value to 0 in the REGLG variable doesn't do anything by itself until I use the REGLG variable with the $VARYING format for writing variable length text. I can specify $VARYING's length as $VARYING100. (which means that the line could be anywhere in length from 1-100, but not greater than 100. Or I can specify $VARYING length-variable -- as I do in the case of the LINE statement in that example. $VARYING is very cool with PROC REPORT because setting a LENGTH of 0 for the length variable will cause REPORT to suppress the LINE text.
Cynthia

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 1921 views
  • 1 like
  • 2 in conversation