%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**
--*;
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.