Hi,
I have master table called Have and in that table there is column called Logic. It has around 100 observations. All of those observations are actually the logic for data processing. How do I read data from that variable and execute it. I tried using call execute but somehow never got that correct. Below is the sample data.
Sr No | Logic |
1 | If rate=10 and principal_amt=100000 then emi=5000 |
2 | If rate=9 and principal_amt=100000 then emi=4800 |
3 | If income>1000000 then risk=10 |
4 | If income<20000 then risk=80 |
5 | if category='New Customer' then do; rate=10; risk=20; end; |
My Logic variable can be upto 1000 character variable. Now, how do I execute below code .
Data want;
set source;
If rate=10 and principal_amt=100000 then emi=5000;
If rate=9 and principal_amt=100000 then emi=4800;
If income>1000000 then risk=10;
If income<20000 then risk=80;
if category='New Customer' then do; rate=10; risk=20; end;
run;
Any help is really appreciated
Data logic;
input Sr_No Logic $2-100;
infile datalines4 truncover;
datalines4;
1 If rate=10 and principal_amt=100000 then emi=5000
2 If rate=9 and principal_amt=100000 then emi=4800
3 If income>1000000 then risk=10
4 If income<20000 then risk=80
5 if category='New Customer' then do; rate=10; risk=20; end;
;;;;
run;
data _null_;
set logic end=eof;
if _n_=1 then
do;
call execute('data want; set source;');
end;
call execute(' ' !! catx(' ',Logic,';') !! ' ');
if eof then
do;
call execute('run;');
end;
run;
Data logic;
input Sr_No Logic $2-100;
infile datalines4 truncover;
datalines4;
1 If rate=10 and principal_amt=100000 then emi=5000
2 If rate=9 and principal_amt=100000 then emi=4800
3 If income>1000000 then risk=10
4 If income<20000 then risk=80
5 if category='New Customer' then do; rate=10; risk=20; end;
;;;;
run;
data _null_;
set logic end=eof;
if _n_=1 then
do;
call execute('data want; set source;');
end;
call execute(' ' !! catx(' ',Logic,';') !! ' ');
if eof then
do;
call execute('run;');
end;
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.