Hello everyone,
If I have a macro variable and I would like to put quotation marks around it, is there a function to do this?
Thanks
Example:
Have: %let ppl= 001-001 001-002;
Want: "001-001" "001-002"
I think you mean quotes.
Are you you creatimg this manually? How do you plan to use it? There are ways but not easily so sometimes easier to do depending on how you create macro variable or how you plan to use it.
Thanks Reeza for your response. I am using it as follows:
proc sql;
select distinct subject into :ppl separated by ' '
from opt.sv
where foldername = "Early Study Withdrawal";
quit;
proc print data=opt.sv(where=(subject = &ppl));
var subject folder svdtc;
run;
ERROR: WHERE clause operator requires compatible variables.
I dont know why my SQL code threw in a smiley face! 🙂
I think you may want something like
proc sql;
select distinct quote(strip(subject)) into :ppl separated by ' '
from opt.sv
where foldername = "Early Study Withdrawal";
quit;
proc print data=opt.sv(where=(subject in( &ppl)));
var subject folder svdtc;
run;
The strip is to remove trailing blanks within the quotes which might cause issues with the comparison
And you didn't want to test if subject was equal to a list of values but a member of the list.
Note that STRIP() will also remove any existing leading spaces, which could cause values to not match. It is safer to use TRIM() in this case.
Thanks so much BallardW.....that was super! Really appreciate your help. 🙂
%let ppl= 001-001 001-002;
%let want="%sysfunc(tranwrd(%cmpres(&ppl),%str( ),%str(" ")))";
%put &want;
Thanks Xia for that very interesting method...I am going to have to figure out what each element is doing! Complicated but quite impressive! Thx again! 🙂
Here is an alternative way by PRXCHANGE() .
%let ppl= 001-001 001-002;
%let want=%sysfunc(prxchange(s/(\S+)/"\1"/,-1,&ppl));
%put &want;
I'm a big fan of this solution, it helps to use a macro variable date within teradata.
Excellent!
Hi,
just a small suggestion , when comparing text variable making them into same case, this will help resolve mis-match due to case inconsistency in the data..
Hope that helps
Rgds,
Abhi
Hello,
I have this solution, the result is correct but, i have the error of evaluate.
Can someone help me understand his provenance?
Thank you
%macro tt();
%global f;
%let a=001-001 001-002;
%let f= %str( );
%do i=1 %to %sysfunc(countw(&a.,' '));
%let f=%sysfunc(catx(%str( ),&f.,"%scan(&a.,&i,' ')") );
%end;
%mend;
%tt;
%put =&f.;
///////
ERROR: %SYSEVALF function has no expression to evaluate.
%put =&f.; ="001-001" "001-002"
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!
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.
Ready to level-up your skills? Choose your own adventure.