i have values as
val
100
98
37.09876554
32.7653243
76
and i want to have length as 5.2 only if i have integer and i use val1=input(val,best4.) but somehow it gives blank whenevr i have whole digits such as 100, 98, 76 and makes the deimals 37.09.
Is there anyway where i can keep whole digits as it is reduce decimals?
You can use the bestd format like this
data have;
input val;
format val bestd6.2;
datalines;
100
98
37.09876554
32.7653243
76
;
I'm not sure I understand this. You want to display integers without decimals and non-integers with two decimals, or?
yes, integers without decimals and non-integers with 2 decimals
You can use the bestd format like this
data have;
input val;
format val bestd6.2;
datalines;
100
98
37.09876554
32.7653243
76
;
Hi:
Internally, as SAS stores the data, whether or not there are decimals doesn't make a difference. The only place it makes a difference is in the display of the values, such as in a report. PROC PRINT won't allow a different format for every variable value -- unless you convert your number to a character string. However, PROC REPORT will allow you to use a different format for different values in a column.
For example, consider the program and output below:
The "helper" variable TESTDEC is being used as a simple way to tell whether the number needs decimal places in the format or not.
CALL DEFINE with PROC REPORT allows you to apply a format conditionally to a data cell. CALL DEFINE can only be used in a COMPUTE block, as shown.
Hope this helps point you in a direction,
Cynthia
data have;
input Var;
datalines;
100
98
37.0834224
32.766523
76
;
run;
data want;
set have;
if find(Var, '.', '') ge 1 then Test = round(var,.1);
else Test = Var;
run;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.