DATA Step, Macro, Functions and more

How to make a row blank which is consisting integer value

Reply
Occasional Contributor
Posts: 13

How to make a row blank which is consisting integer value

Hi,

 

I am having a pdf report on sas where some rows are having value with 0.00% or else 0.0000000. The requirement is to make that row blank if the value is 0.

 

Can anyone suggest me what can be done to solve the issue?

 

 

Super User
Posts: 7,827

Re: How to make a row blank which is consisting integer value

For display purposes, I would create character variables, and conditionally fill those variables with put() if the value is not zero. Then use the character variables in proc print or whatever.

In proc report, you can use a compute block to achieve no output when the value is zero.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Occasional Contributor
Posts: 13

Re: How to make a row blank which is consisting integer value

Posted in reply to KurtBremser

First of all thnak you for your suggesion.

 

For Proc Report I have tried this one :

compute index=0;

if index ^= '0' then do;

if maths='0' and history='0' and science='0'

text ' ';

 

Its not working.Can you please help me out with what is the correct one?

 

 

Thanks,

Puja

Super User
Posts: 7,827

Re: How to make a row blank which is consisting integer value

define index_char / computed;
compute index_char;
  if index ne 0
  then index_char = put(index,7.2);
  else index_char = " ";
endcomp;

See http://support.sas.com/documentation/cdl/en/proc/69850/HTML/default/viewer.htm#p0rb7cj6wzrl5sn0zelfb... and other examples of the report procedure.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Occasional Contributor
Posts: 13

Re: How to make a row blank which is consisting integer value

Posted in reply to KurtBremser
I have tried this one. But is not reflected here.

Compute col1_char;
If index_id ne 0
Then do;
If col1='0'
Then do;
Col1_char=put(col1,7.2);
Col1_char=" ";
Endcomp;

Can you please let me know where i am doing mistake?

The demo report is attached with this.

##- Please type your reply above this line. Simple formatting, no
attachments. -##
Super User
Posts: 7,827

Re: How to make a row blank which is consisting integer value

Look at the log!

 

You have do statements without corresponding end statements.

 

And stop writing spaghetti code; proper formatting (indentation) makes the logic visible:

compute col1_char;
  If index_id ne 0
  then do;
    If col1 = 0 /* assuming col1 is numeric, no quotes! */
    then do;
      col1_char = put(col1,7.2);
    end;
    else do;
      col1_char = " ";
    end;
  end;
endcomp;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Occasional Contributor
Posts: 13

Re: How to make a row blank which is consisting integer value

Posted in reply to KurtBremser
Hi,

Yeah sorry i havnt put in with proper indentation.

One thing, here i am trying to put blank whereever the value of the column
is zero.. so in this case, i feel col1_char=" " should not be in the else
part. Am i right?

##- Please type your reply above this line. Simple formatting, no
attachments. -##
Super User
Posts: 7,827

Re: How to make a row blank which is consisting integer value

Well, you have to decide about the logic. I just made the process more visible.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 11,343

Re: How to make a row blank which is consisting integer value

One approach that may work is to use a custom format so that values of 0 display as ' '. However depending on how many columns and ranges of values you are dealing with this could become cumbersome.

Ask a Question
Discussion stats
  • 8 replies
  • 181 views
  • 0 likes
  • 3 in conversation