BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
lmyers2
Obsidian | Level 7

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.);

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

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;

PGStats_0-1615942126724.png

 

PG

View solution in original post

3 REPLIES 3
PGStats
Opal | Level 21

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;

PGStats_0-1615942126724.png

 

PG
lmyers2
Obsidian | Level 7
Wow! Thanks! That worked perfectly!!
ChrisNZ
Tourmaline | Level 20

Like this?

NB=resolve( '%sysevalf(' || PF_RATIO || ')' );

Input it to get a numeric.

 

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 2408 views
  • 2 likes
  • 3 in conversation