This macro assumes a so-called macro variable array. I am not a big fan, but sometimes you have no choice.I would have written the macro a bit differently, but the concept remains the same.
%*-- returns a macro-quoted comma-separated double-quoted text,
given an mac var array root1 - rootn, where root0 evaluates to n.
if root0 does not exists then root should exists as this macro
returns its value enquoted --*;
%macro qCsqv(root=);
%if not %symexist(&root.0) %then %do;
%*;%qsysfunc(quote(&&&root))
%return;
%end;
%local i;
%do i = 1 %to &&&root.0;
%if &i > 1 %then %*;%str(, );
%*;%qsysfunc(quote(&&&root.&i))
%end;
%mend qCsqv;
%*-- test1. when p0 exists --*;
%let p0 = 3;
%let p1 = a;
%let p2 = b;
%let p3 = c;
%put %qCsqv(root=p);
%*-- on log
"a", "b", "c"
--*;
%*-- test2. when p0 does not exist --*;
%symdel p0 p1 p2 p3;
%let p = hello;
%put %qCsqv(root=p);
%*-- on log
"hello"
--*;
Cynthia, I figured out that addingseparated by ' ' in proc sql also removes trailing blanks. of course, it makes not sense when you are selecting only one record but for removing trailing blanks.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.