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;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.