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

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

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;

View solution in original post

6 REPLIES 6
JohnChen_TW
Quartz | Level 8
Well, this will resolve only the first line of data. Thank you.
Kalind_Patel
Lapis Lazuli | Level 10

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

 

 

 

JohnChen_TW
Quartz | Level 8
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.
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;
JohnChen_TW
Quartz | Level 8
Hi RW9,

Thanks for your answer! It resolved my question. 🙂

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

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
  • 6 replies
  • 6415 views
  • 10 likes
  • 4 in conversation