%macro getValueOf(var, data=_last_, obsno=1);
%global getValueOf_ds;
%local rc;
%if &getValueOf_ds= %then %do;
%let getValueOf_ds=%sysfunc(open(&data,i));
%if &getValueOf_ds=0 %then %goto cleanUp;
%end;
%syscall set(getValueOf_ds);
%let rc = %sysfunc(fetchobs(&getValueOf_ds, &obsno));
%if &rc ^= 0 %then %goto cleanUp;
%*;&&&var
%return;
%cleanUp:
%if &getValueOf_ds>0 %then %let rc = %sysfunc(close(&getValueOf_ds));
%symdel getValueOf_ds;
%mend getValueOf;
/* checking */
data class;
set sashelp.class(obs=1);
run;
%put name=%getValueOf(name);
%put age =%getValueOf(age);
%*-- on log
name=Alfred
age =14
--*;
%getValueOf(obsno=0) %*-- to close the data set --*;
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.