Hi, I have a dataset that is interest rate, most of the data is in a 2 decimal format (eg. 2.45), but some rows have a 4 decimals (eg. 2.4678) format. How do I chose the data that has only the 4 decimals? Thanks
data have;
k=2.4678;
output;
k=2.34;
output;
k=2;
output;
k=2.4450;
output;
k=2.4400;
run;
data want;
set have;
if mod(k*1e4,10);
run;
/*or where*/
where mod(k*1e4,10);
data have;
k=2.4678;
output;
k=2.34;
output;
k=2;
output;
k=2.4450;
output;
k=2.4400;
run;
data want;
set have;
if mod(k*1e4,10);
run;
/*or where*/
where mod(k*1e4,10);
The solution from @novinosrin fails if k=2.46789.
How about this:
data want;
set have;
ychar=put(k,best12.);
if length(strip(scan(ychar,2,'.')))=4;
run;
And @Tom makes a good point too...
Yes, that's correct. The solution assumes based upon OP wrote "most of the data is in a 2 decimal format (eg. 2.45), but some rows have a 4 decimals (eg. 2.4678) format."
@podarum wrote:
Hi, I have a dataset that is interest rate, most of the data is in a 2 decimal format (eg. 2.45), but some rows have a 4 decimals (eg. 2.4678) format. How do I chose the data that has only the 4 decimals? Thanks
If the field is not a character string then you don't.
How can you tell the difference between a value that was original written as '2.50' and a value written as '2.500'? They are the same number.
Another way:
if length( scan( put(VAR,best32. -l), 2, '. ' ) ) = 4;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.