Hi.
If you have very large dataset, use the tranwrd function and resolve function with %sysevalf :
DATA temp1;
INPUT formula $ var1 ;
DATALINES;
2*var1 1
23*var1 2
12*var1 5
;
data result;
set temp1;
temp=tranwrd(formula ,'var1',strip(var1));
result=resolve('%sysevalf('||temp||')');
run;
If you have not very large dataset, CALL EXECUTE can generate the statements for each record to calculate the result:
DATA temp1;
INPUT formula $ var1 ;
DATALINES;
2*var1 1
23*var1 2
12*var1 5
;
data _null_;
set temp1 end=last;
if _n_=1 then call execute('data _result;');
call execute('var1='||var1||';');
call execute('formula="'||formula||'";');
call execute('result='||formula||';');
call execute('output;');
if last then call execute('run;');
run;
Ksharp
Hi.
If you have very large dataset, use the tranwrd function and resolve function with %sysevalf :
DATA temp1;
INPUT formula $ var1 ;
DATALINES;
2*var1 1
23*var1 2
12*var1 5
;
data result;
set temp1;
temp=tranwrd(formula ,'var1',strip(var1));
result=resolve('%sysevalf('||temp||')');
run;
If you have not very large dataset, CALL EXECUTE can generate the statements for each record to calculate the result:
DATA temp1;
INPUT formula $ var1 ;
DATALINES;
2*var1 1
23*var1 2
12*var1 5
;
data _null_;
set temp1 end=last;
if _n_=1 then call execute('data _result;');
call execute('var1='||var1||';');
call execute('formula="'||formula||'";');
call execute('result='||formula||';');
call execute('output;');
if last then call execute('run;');
run;
Ksharp
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.