DATA Step, Macro, Functions and more

Suppress a column in Proc Report

Accepted Solution Solved
Reply
Contributor
Posts: 25
Accepted Solution

Suppress a column in Proc Report

In the proc report example below, is there a way to hide or suppress the column where y=4 from the output?

 

data a;

input x 1. y 1.;

datalines;

 

14

24

33

22

;

run;

proc report data=a;

columns x y;

define x / group;

define y / across;

define n / format=8.;

run;

 


Accepted Solutions
Solution
‎06-12-2018 09:36 AM
SAS Super FREQ
Posts: 9,365

Re: Suppress a column in Proc Report

Hi:

  Since you made both Y and Z Across variables and you're getting the count in every cell, it's going to be hard to suppress the Y=4 column when the data is structured the way you show.

 

  If you restructured your data, so that there was only 1 value on every row and a type indicator that was character, that would be easier to suppress the entire column when Y=4, as shown below:

restructure_data_suppress_4.png 

 

If you're OK seeing a column for Y=4, but with missing instead of a count, then you could use a COMPUTE block to change the value to 0 or missing. But the challenge with that is that the Y column would still be there and since Y is an ACROSS variable in your example code, you would have to use an absolute column number in the COMPUTE block.

 

  I just used a datalines for the restructured data to show you how it would work. You could also write a program to restructure what you have into this form. Hope this helps,

 

Cynthia

View solution in original post


All Replies
Valued Guide
Posts: 589

Re: Suppress a column in Proc Report

Use a where condition near data

 

proc report data=a(where=(y<>4));
Thanks,
Suryakiran
Super User
Posts: 23,663

Re: Suppress a column in Proc Report

proc report data=a;

WHERE y ne 4;

columns x y;

define x / group;

define y / across;

define n / format=8.;

run;

 

Most procs support a WHERE statement. 

 

 

Contributor
Posts: 25

Re: Suppress a column in Proc Report

[ Edited ]

Thanks to both respondents.  I should have been clearer, I actually plan to use more variables and would like the observations that contain y=4 to be in those distributions.   The solution you recommended wouldn't allow that.   Is there a way to just hide the column from the output for display purposes?

Super User
Posts: 23,663

Re: Suppress a column in Proc Report

Provide more details, preferably some more data and an example of what you want as output.

 


@Batman wrote:

Thanks to both respondents.  I should have been clearer, I actually plan to use more variables and would like the observations that contain y=4 to be in those distributions.   The solution you recommended wouldn't allow that.   Is there a way to just hide the column from the output for display purposes?


 

 

Contributor
Posts: 25

Re: Suppress a column in Proc Report

Here is a better example.   I'd like to hide the column where y=4, but I'd still like all values of z to appear.

 

 

data a;

input x 1. y 1. z 1.;

datalines;

 

146

240

330

220

;

run;

proc report data=a;

columns x y z;

define x / group;

define y / across;

define z / across;

define n / format=8.;

run;

 

Super User
Posts: 23,663

Re: Suppress a column in Proc Report

Then I would suggest either a computed column that sets it to blank if it's 4, or a custom format that masks it if it's 4. 

 

 

Contributor
Posts: 25

Re: Suppress a column in Proc Report

Do you have a sample of either?   How can I write a compute block for a value of a variable that is defined as an across variable?

Solution
‎06-12-2018 09:36 AM
SAS Super FREQ
Posts: 9,365

Re: Suppress a column in Proc Report

Hi:

  Since you made both Y and Z Across variables and you're getting the count in every cell, it's going to be hard to suppress the Y=4 column when the data is structured the way you show.

 

  If you restructured your data, so that there was only 1 value on every row and a type indicator that was character, that would be easier to suppress the entire column when Y=4, as shown below:

restructure_data_suppress_4.png 

 

If you're OK seeing a column for Y=4, but with missing instead of a count, then you could use a COMPUTE block to change the value to 0 or missing. But the challenge with that is that the Y column would still be there and since Y is an ACROSS variable in your example code, you would have to use an absolute column number in the COMPUTE block.

 

  I just used a datalines for the restructured data to show you how it would work. You could also write a program to restructure what you have into this form. Hope this helps,

 

Cynthia

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 8 replies
  • 148 views
  • 2 likes
  • 4 in conversation