%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**
--*;
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.