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

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 2296 views
  • 2 likes
  • 3 in conversation