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.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.