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

Hello, I am a student working on a project and I have come across a problem that I can't solve.

 

I am reading in data that deals with colleges and one of the variables is a ratio.

 

The problem is that the ratios were entered in two different ways, sometimes they were entered in the standard 'X : Y' format and other times they were simply entered as a decimal such as 1.75.

 

Is there a way to create an informat that will be able to read in the ratios along with the decimals? Thanks. 

 

Example: 

2.159027778
1.790277778
33 : 67
2.240972222
1.954166667
 
2.56875
 
0.602083333
0.847916667
39 : 61
1 ACCEPTED SOLUTION

Accepted Solutions
Shmuel
Garnet | Level 18

You can overcome the situation by reading the ratio in an alphanumeric temporary variable 

defined with informat $12, then code:

 

if indexc(temp_var,':')

   then ratio = input(scan(temp_var,1,':'),best3.) / input(scan(temp_var,2,':'),best3.);

   else ratio = input(temp_var, best12.9 );

View solution in original post

5 REPLIES 5
ballardw
Super User

As pasted there is some other character between the numerals and the : . Is that the actual case in your data? If so what is the character as you see it? Sometimes things pasted into the forum, especially from a non-plain text source such as EXCEL, acquire additional "stuff".

If this is a ratio such as 39:61 I would suspect that you want the division of 39/61 done, correct?

Peadymarvin
Calcite | Level 5

I pasted from excel but I don't see anything else besides the decimal and the colon between numbers?

 

 

Yes that would be the end goal

ballardw
Super User

It may be my work browser, Internet Explorer, but just looking at the pasted values there is a space between the colon and the digits on each side.

Copied and paste from the first post:

39 : 61

 

Typed:

39:61

Shmuel
Garnet | Level 18

You can overcome the situation by reading the ratio in an alphanumeric temporary variable 

defined with informat $12, then code:

 

if indexc(temp_var,':')

   then ratio = input(scan(temp_var,1,':'),best3.) / input(scan(temp_var,2,':'),best3.);

   else ratio = input(temp_var, best12.9 );

Peadymarvin
Calcite | Level 5

Thanks! It worked 🙂

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 5 replies
  • 1148 views
  • 1 like
  • 3 in conversation