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.

 

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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