## Extract Number from a character variable

Solved
Occasional Contributor
Posts: 11

# Extract Number from a character variable

I imported data from CSV files and one of the variables is character (should be numeric).

The variables has numbers like "1000" and "2000" but some look like "1000..." or "2000...." - they have there extra "..." that vary in lenght at the end. How can I extract just the numbers?

Accepted Solutions
Solution
‎11-30-2016 03:21 PM
Super Contributor
Posts: 320

## Re: Extract Number from a character variable

```num_val = input(compress(char_val,,'kd'),best32.);
```

Now, I assume you have only positive integer here.  If decimal or negative are possible, then you may need much more complicated code to deal with that possibility (as you have . and such in your examples and can't just keep all . )...

All Replies
Solution
‎11-30-2016 03:21 PM
Super Contributor
Posts: 320

## Re: Extract Number from a character variable

```num_val = input(compress(char_val,,'kd'),best32.);
```

Now, I assume you have only positive integer here.  If decimal or negative are possible, then you may need much more complicated code to deal with that possibility (as you have . and such in your examples and can't just keep all . )...

Occasional Contributor
Posts: 11