%macro vars(data=, dlm=%str( ));
%local lib mem ds where keep first name;
%*-- data should exists --*;
%let data = %upcase(&data);
%if not %sysfunc(exist(&data)) %then %do;
%put ERROR:(vars) data=&data does not exists;
%return;
%end;
%*-- extract libname and memname and prepare ds options --*;
%let lib = %scan(&data,1,.);
%let mem = %scan(&data,2,.);
%if &mem = %then %do;
%let mem = &lib;
%let lib = WORK;
%end;
%let where = (libname="&lib" and memname="&mem");
%let keep = libname memname name;
%*-- extract var names from sashelp.vcolumn view --*;
%let ds = %sysfunc(open(sashelp.vcolumn(keep=&keep where=&where),is));
%if &ds=0 %then %do;
%put ERROR:(vars) vcolumn of &data cannot be opened;
%return;
%end;
%syscall set(ds);
%let first = 1;
%do %while(%sysfunc(fetch(&ds))=0);
%if &first %then %let first = 0;
%else %*;&dlm;
%*;%trim(&name)
%end;
%let ds = %sysfunc(close(&ds));
%mend vars;
%*-- check --*;
%put ***%vars(data=sashelp.class)***;
%put ***%vars(data=sashelp.class, dlm=%str(, ))***;
%*-- on log
**Name Sex Age Height Weight**
**Name, Sex, Age, Height, Weight**
--*;
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.