DATA Step, Macro, Functions and more

convert from 0.00% to blank for a column value

Reply
Occasional Contributor
Posts: 13

convert from 0.00% to blank for a column value

Spoiler
 

Hi,

 

 

The requirement is to check the value of a column if '0.00%' then it would be blank.

First of all to check for a condition that if the value of a column is 0 then make it as '0.00%'. I have done it to make it as char fist using put() then || with percentage.Its working fine.

For the next case While I am trying to check if the column value is '0.00%' then make it as blank,dats not working. I feel that when I am trying to check if the value is equal to '0.00%' then it simply makes it as blank || %. which cant match the condition anymore. thats why expected output is not coming.

can you please help me how to resolve this one??

 

 

Thanks,

Puja

Super User
Posts: 19,815

Re: convert from 0.00% to blank for a column value

Show your code, and provide sample data please. 

Frequent Contributor
Posts: 96

Re: convert from 0.00% to blank for a column value

Hi @PujaDas;

 

If you want to change numeric variable to blank,

you have to use options missing="";

 

you can also use format or picture format, as @Reeza asked for the code, it will give more clarification to us that what you actually want to do!

Super User
Posts: 7,804

Re: convert from 0.00% to blank for a column value

What purpose does the intermediate step serve, when the end result should be a blank for zero anyway?

Rather do

length charval $10;
if numval = 0
then charval = " ";
else charval = put(numval,percent10.2);
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Occasional Contributor
Posts: 13

Re: convert from 0.00% to blank for a column value

Posted in reply to KurtBremser

Sample data :

                           OnedayRound     YTD      NAV      roundedNAV

 

Fund1 Details      0.00%                0.00%   0.00       0.000

 

I have tried the below two but the desired output is not coming.

NOTE : value of the column is converted to char to || percentage Sign.

 

CODE 1 :

Compute Index_id;

if Index_Id ne '0' then

    if( OnedatRound =(' ' | '0.00%') & YTD=(' ' | '0.00%') & NAV=(' ' | '0.00) & roundedNAV=(' ' | '0.000'))

    tehn do;

       OnedayRound=' ';    

       YTD=' ';

       NAV=' ';

       roundedNAV=' ';

  end;

end;

endcomp;;

 

 

CODE2Smiley Sadhave tried only for YTD column)

compute percentage;

if Index_Id ne '0' then

   if(YTD='0.00%')

   YTD_1=' ';

      if (YTD_1=(' ' || Percent_sign)

      then do;

      YTD=' ';

      end;

end;

endcomp;

Super User
Posts: 7,804

Re: convert from 0.00% to blank for a column value

Do not confuse displayed values with stored values, and stay true to variable types.

 

If a variable is defined as numeric, do not use strings for comparison.

A numeric variable with a percentw.d format will display as 0.00%, but the value will be 0.

So

if numvar = '0.00%'

will never work, but

if numvar = 0

will work.

To get more specific information, I suggest you post the output of proc contents for the dataset used in the proc report.

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

Re: convert from 0.00% to blank for a column value

Posted in reply to KurtBremser

YTD2= PUT(ROUND(YTD_1,.01),5.2);

IF YTD2='0' THEN YTD_1='0.00';

 

YTD= YTD2 || PERCENT_SIGN;

 

its been don ein the existing code for some purpose.We cant avoid that. So its not in numeric.

 

Occasional Contributor
Posts: 13

Re: convert from 0.00% to blank for a column value

Posted in reply to KurtBremser

its already been converted into char in the existing code.I cant ignore that.

 

YTD2=put(round(YTD1,.01),5.2);

if YTD2='0' then YTD='0.00';

 

YTD=YTD2 || Percent_Sign;

 

 

Super User
Posts: 7,804

Re: convert from 0.00% to blank for a column value

So you use the 5.2 format in the put function, and then expect ytd2 to be just '0'?

Think again.

16         data _null_;
17         ytd1 = 0;
18         YTD2=put(round(YTD1,.01),5.2);
19         put ytd2=;
20         run;

YTD2=0.00

 

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Ask a Question
Discussion stats
  • 8 replies
  • 232 views
  • 0 likes
  • 4 in conversation