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

Hello,

 

I have this:

 

%let have=123,456; 
/*This will always be a number with commas. It can also be 123,456,789*/

I just want another macro variable having all numbers except for the comma.

 

Thanks

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

An alternative to the above, which will remove other non-numeric characters should there be any (not just the comma) is the following, which removes only the commas.

 

%let have=123,456; 
%let want=%sysfunc(compress(%bquote(&have),%str(,)));
%put &=want;
--
Paige Miller

View solution in original post

8 REPLIES 8
novinosrin
Tourmaline | Level 20
%let have=123,456; 

%let want=%sysfunc(compress(%superq(have),,kd));
%put &=want;

%let have=123,456;
491
492 %let want=%sysfunc(compress(%superq(have),,kd));
493 %put &=want;
WANT=123456

PaigeMiller
Diamond | Level 26

An alternative to the above, which will remove other non-numeric characters should there be any (not just the comma) is the following, which removes only the commas.

 

%let have=123,456; 
%let want=%sysfunc(compress(%bquote(&have),%str(,)));
%put &=want;
--
Paige Miller
novinosrin
Tourmaline | Level 20

Excellent thinking 🙂  as @PaigeMiller  quant miller thinks in terms of dollars i.e what if the value was $100,000,000

 

rich man, hopefully he buys me a coffee

 

I hope OP got the analogy lol

PaigeMiller
Diamond | Level 26

Well, again, @novinosrin , we don't know the exact problem, we have been told only a very simplified version of the problem, and your solution may be fine and mine may not work on the real problem.

--
Paige Miller
david27
Quartz | Level 8

Yes It is perfect.

But One question:

Why dont you have &have.? (instead there is just "have").

 

Why is it that way?

 

Thanks

novinosrin
Tourmaline | Level 20

just syntax,

 

The argument of %superq doesn't require a macro trigger &  for the resolution to occur. I think it's a touch faster as it immediately quotes the value of a macro variable with no further resolution to occur by quoting the resolved value of the macro var. 

 

On the other %bquote does give room for further resolution should a macro var resolves to a value that is a macro trigger.

novinosrin
Tourmaline | Level 20

Also I love superq

 

The name sounds appealing besides the execution performance lol 🙂

ballardw
Super User

Sometimes prevention is better than correction.

How is that macro variable with a comma made in the first place?

 

In places where I need the same value in multiple macro variables with such differences I make them at the same time with different rules.

 

Note that since commas are the default delimiter for macro parameters and many functions the idea of placing commas into macro variables is generally quite suspect to begin with.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 8 replies
  • 1261 views
  • 4 likes
  • 4 in conversation