%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**
--*;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.