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!
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!
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!
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
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;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.