BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Sathish_jammy
Lapis Lazuli | Level 10
data have;
input abc $;
cards;
1.0 MG
0.25#
*1
2.5 UG
run;


data want;
set have;
a1 = compress(abc,'#*','s','a');
run;

I need only the numeric value. while using the compress func an ERROR occurred:

 

The COMPRESS function call has too many arguments.

Please suggest me any methods to solve.

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

READ THE DOCUMENTATION!

 

From the "modifier" part:

 

k or K   keeps the characters in the list instead of removing them.

 

So you want to keep digits and dots, just use a list of all digits and the dot as second parameter, and k as the third.

data have;
input abc $;
cards;
1.0 MG
0.25#
*1
2.5 UG
;
run;

data want;
set have;
a1 = compress(abc,'0123456789.','k');
run;

Or use a combination of parameters:

data want;
set have;
a1 = compress(abc,'.','kd');
run;

 

View solution in original post

4 REPLIES 4
Shmuel
Garnet | Level 18

The 2nd argument of compress is a string contains the delimiters or characters to ignore.

There is a 3rd argument with special means. In your case "kd" means keep digits only:

   a1 = compress(abc, , 'kd');

 

You better look at the documentation.

Sathish_jammy
Lapis Lazuli | Level 10

If i use 'kd' in compress then it delete '.' punctuation in (1.5, 2.5, 1.0) so the value should like (15 , 25, 10)

I need value in decimal as same as in my dataset.

Kurt_Bremser
Super User

READ THE DOCUMENTATION!

 

From the "modifier" part:

 

k or K   keeps the characters in the list instead of removing them.

 

So you want to keep digits and dots, just use a list of all digits and the dot as second parameter, and k as the third.

data have;
input abc $;
cards;
1.0 MG
0.25#
*1
2.5 UG
;
run;

data want;
set have;
a1 = compress(abc,'0123456789.','k');
run;

Or use a combination of parameters:

data want;
set have;
a1 = compress(abc,'.','kd');
run;

 

Sathish_jammy
Lapis Lazuli | Level 10

Thank u so much! @Kurt_Bremser @Shmuel

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 1806 views
  • 1 like
  • 3 in conversation