DATA Step, Macro, Functions and more

Compress func has too many arguments

Accepted Solution Solved
Reply
Contributor
Posts: 20
Accepted Solution

Compress func has too many arguments

[ Edited ]
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.


Accepted Solutions
Solution
Friday
Super User
Posts: 10,209

Re: Compress func has too many arguments

[ Edited ]
Posted in reply to Sathish_jammy

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;

 

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code

View solution in original post


All Replies
Trusted Advisor
Posts: 1,837

Re: Compress func has too many arguments

[ Edited ]
Posted in reply to Sathish_jammy

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.

Contributor
Posts: 20

Re: Compress func has too many arguments

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.

Solution
Friday
Super User
Posts: 10,209

Re: Compress func has too many arguments

[ Edited ]
Posted in reply to Sathish_jammy

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;

 

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Contributor
Posts: 20

Re: Compress func has too many arguments

Posted in reply to KurtBremser

Thank u so much! @KurtBremser @Shmuel

☑ This topic is solved.

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

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