## Compress Function using a decimal with range

Solved
Frequent Contributor
Posts: 86

# Compress Function using a decimal with range

Hi all,

I'm trying to compress a data like "<= 0.3" to "0.3", but COMPRESS FUNCTION seems that just can compress ALL punctuation marks at one time...So, is there any better way to compress only "<= " and keep the decimal?

However, this is just one example of my data. I need a resolution for all cases like this. Thank you!

Original    Compressed

<= 0.3             0.3

0.58             0.58

> 1.2              1.2

45                45

Accepted Solutions
Solution
‎12-15-2016 09:39 PM
Super User
Posts: 9,599

## Re: Compress Function using a decimal with range

Posted in reply to JohnChen_TW

Well, its likely that you have other maths symbols, so maybe reverse the thinking, the below "k"eeps, only "d"igits and the decimal:

```data test;
original = "<= 0.3";
compressed = compress(original,'.','kd');
run;```

All Replies
Super User
Posts: 10,217

## Re: Compress Function using a decimal with range

Posted in reply to JohnChen_TW
``````data test;
original = "<= 0.3";
compressed = compress(original,'<=');
run;

proc print data=test;
run;``````

works.

Output:

```Obs    original    compressed

1      <= 0.3        0.3
```
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Frequent Contributor
Posts: 86

## Re: Compress Function using a decimal with range

Posted in reply to KurtBremser
Well, this will resolve only the first line of data. Thank you.
Frequent Contributor
Posts: 96

## Re: Compress Function using a decimal with range

[ Edited ]
Posted in reply to JohnChen_TW

Hi @JohnChen_TW;

You can use this line :

compressed = compress(original,'<=');

this will remove <= combination from the variaable;

But, on the third line you provided another special character in sample data,

so below code will not compress this special character;

so in this case you can use this code:

``````data test;
set test;
compressed=compress(original,'<');
compressed=compress(original,'=');
compressed=compress(original,'>');
run;``````

it will remove all the possible combination like: <=, <, =, >, => from the variable

Frequent Contributor
Posts: 86

## Re: Compress Function using a decimal with range

Posted in reply to Kalind_Patel
Kalind_Patel, thanks for your suggestion.
Well, maybe my question is unclear. The point is that I need to keep only "0.1", "1.5", ...and so on.
Thank you.
Solution
‎12-15-2016 09:39 PM
Super User
Posts: 9,599

## Re: Compress Function using a decimal with range

Posted in reply to JohnChen_TW

Well, its likely that you have other maths symbols, so maybe reverse the thinking, the below "k"eeps, only "d"igits and the decimal:

```data test;
original = "<= 0.3";
compressed = compress(original,'.','kd');
run;```
Frequent Contributor
Posts: 86

## Re: Compress Function using a decimal with range

Hi RW9,

Thanks for your answer! It resolved my question.
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
• 6 replies
• 510 views
• 10 likes
• 4 in conversation