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
Show your code, and provide sample data please.
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);
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;
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.
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.
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;
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 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.