%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 --*;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.