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.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.