%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 --*;
Navigate AI governance with SAS tools for compliance and ethical AI practices. Try SAS Ai Navigator for free for the first six months.
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.