Hello
I have data that looks like "70/40" but want to convert it from a character variable to a numeric fraction so I can get the decimal (1.75). I've tried the following within data steps but get errors to both saying that "fract" isn't recognized. Any ideas? Thanks for the help! I'm using SAS 9.4.
format PF_RATIO fract.;
PFRATIO=informat(PF_RATIO, FRACT6.);
Try
data test;
do pf_ratio = "70/40", "1.75";
PFRATIO = input(scan(pf_ratio, 1, "/"), best.) / coalesce(input(scan(pf_ratio, 2, "/"), ?? best.), 1);
output;
end;
run;
Try
data test;
do pf_ratio = "70/40", "1.75";
PFRATIO = input(scan(pf_ratio, 1, "/"), best.) / coalesce(input(scan(pf_ratio, 2, "/"), ?? best.), 1);
output;
end;
run;
Like this?
NB=resolve( '%sysevalf(' || PF_RATIO || ')' );
Input it to get a numeric.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.