%macro x_vars(dataset,obs) ; %*--posted by Phil Mason to sas-l, 6-19-98--; %* DATASET is the dataset name ; %* OBS is the observation number to turn into macro variables ; * Open the dataset ; %let dsid=%sysfunc(open(&dataset)) ; * Read an observation ; %let rc=%sysfunc(fetch(&dsid)) ; * Get the number of variables ; %let nvars=%sysfunc(attrn(&dsid,nvars)) ; * Make a Global macro variable for each dataset variable ; %do i=1 %to &nvars ; %let varname=%sysfunc(varname(&dsid,&i)) ; %global &varname ; %end ; * Assign each variable value to a macro variable ; %syscall set(dsid) ; * Read the values into the corresponding macro variables ; %let rc=%sysfunc(fetchobs(&dsid,&obs)) ; * Close the dataset ; %let rc2=%sysfunc(close(&dsid)) ; %mend x_vars ;