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
Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.
Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.
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.