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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.