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.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: