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
⏰
Today is the last day to save with the early bird rate! Register today for just $695 - $100 off the standard rate.
Plus, pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.