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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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