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 out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.