BookmarkSubscribeRSS Feed
PujaDas
Calcite | Level 5
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

8 REPLIES 8
Reeza
Super User

Show your code, and provide sample data please. 

Kalind_Patel
Lapis Lazuli | Level 10

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!

Kurt_Bremser
Super User

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);
PujaDas
Calcite | Level 5

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;;

 

 

CODE2:(have 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;

Kurt_Bremser
Super User

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.

PujaDas
Calcite | Level 5

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.

 

PujaDas
Calcite | Level 5

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;

 

 

Kurt_Bremser
Super User

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

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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
  • 8 replies
  • 1594 views
  • 0 likes
  • 4 in conversation