%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**
--*;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.