- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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?
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You can use the bestd format like this
data have;
input val;
format val bestd6.2;
datalines;
100
98
37.09876554
32.7653243
76
;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I'm not sure I understand this. You want to display integers without decimals and non-integers with two decimals, or?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
yes, integers without decimals and non-integers with 2 decimals
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You can use the bestd format like this
data have;
input val;
format val bestd6.2;
datalines;
100
98
37.09876554
32.7653243
76
;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;