☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Lapis Lazuli | Level 10

## What is the most efficient way to extract the percent out of parentheses?

``````data have1;
infile datalines dsd dlm=",";
input number \$;
datalines;
5 (31.4),
3 (12.4),
38 (71.3)
;
run;``````

Hi, i'm trying to extract then numbers out of the percent and turn them into

numerical values.

The desired result should be:

31.4

12.4

71.3

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Super User

## Re: What is the most efficient way to extract the percent out of parentheses?

One way:

```data want;
set have1;
num = input(scan(number,2,'()'),f5.);
run;```

Scan function allows setting what is the delimiter between values of interest so ( and ) seem likely  candidates. The second word would start after the ( and end at the ). Input is the function to turn the value in numeric value with an appropriate informat.

@Hello_there wrote:
``````data have1;
infile datalines dsd dlm=",";
input number \$;
datalines;
5 (31.4),
3 (12.4),
38 (71.3)
;
run;``````

Hi, i'm trying to extract then numbers out of the percent and turn them into

numerical values.

The desired result should be:

31.4

12.4

71.3

Thanks!

5 REPLIES 5
Super User

## Re: What is the most efficient way to extract the percent out of parentheses?

One way:

```data want;
set have1;
num = input(scan(number,2,'()'),f5.);
run;```

Scan function allows setting what is the delimiter between values of interest so ( and ) seem likely  candidates. The second word would start after the ( and end at the ). Input is the function to turn the value in numeric value with an appropriate informat.

@Hello_there wrote:
``````data have1;
infile datalines dsd dlm=",";
input number \$;
datalines;
5 (31.4),
3 (12.4),
38 (71.3)
;
run;``````

Hi, i'm trying to extract then numbers out of the percent and turn them into

numerical values.

The desired result should be:

31.4

12.4

71.3

Thanks!

Lapis Lazuli | Level 10

## Re: What is the most efficient way to extract the percent out of parentheses?

Thank you for the explanation!
Pyrite | Level 9

## Re: What is the most efficient way to extract the percent out of parentheses?

Many thanks. This use of scan function has saved lot of my time. It is very useful where substr is not useful because substr is position specific.

Thank you.

- Dr. Abhijeet Safai

Dr. Abhijeet Safai
Associate Data Analyst
Actu-Real
Obsidian | Level 7

## Re: What is the most efficient way to extract the percent out of parentheses?

data want; set have;
Newvar = substr(oldvar, 1, 1);
Newvar2 = .;
Newvar2 = Newvar;
run;
Super User

## Re: What is the most efficient way to extract the percent out of parentheses?

Slight variation on @ballardw solution which converts it to an actual percentage.

``````data want;
set have1;
num = input(scan(number,1,'()'),f5.);
pct = input(scan(number,2,'()'),f5.)/100;
format pct percent12.1;
run;``````
Discussion stats
• 5 replies
• 483 views
• 6 likes
• 5 in conversation