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

Hi ,

 

new to SAS

 

I have data where i need to extract the % without the "%"

 

Data (character values):
column 1

11(21.2%)

0(0.0%)

9(17.3%)

5.(9.6%)

 

want (in numeric values):

column2

21.2

0.0

17.3

9.6

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

You identified the proper tool for the job.  Try:

 

column_2 = scan(column_1, 1, '(' );

View solution in original post

2 REPLIES 2
Astounding
PROC Star

You identified the proper tool for the job.  Try:

 

column_2 = scan(column_1, 1, '(' );
ballardw
Super User

Scan will return the Character value, so you will need to use an input.

The question, since you are starting with a percent is do you actually want a Percent value: i.e. 21.2% = 0.212 as decimal or 100*0.212 or 21.2

 

Either of the Y or Z yields 21.2 for the first.

data junk;
  x="11(21.2%)";
  y= input(scan(x,2,'(%)'),6.);
  z= input(scan(x,2,'()'),comma6.);
run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 2 replies
  • 907 views
  • 0 likes
  • 3 in conversation