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
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;
%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
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;
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
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.
Yes It is perfect.
But One question:
Why dont you have &have.? (instead there is just "have").
Why is it that way?
Thanks
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.
Also I love superq
The name sounds appealing besides the execution performance lol 🙂
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.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.