BookmarkSubscribeRSS Feed
orangejuss
Fluorite | Level 6

Is it possible to read code block from a table and create a data by using these code blocks as a filter?

Thanks in advance.

 

data filter_data;
input table_name $6. filter $30. ;


DATALINES;
Table1 Count>=3 and date="03feb2021"d
Table2 sum>=100 and count<50
;
RUN;


%macro create(table,filter);

proc sql;
create &table. as select
id,

count(distinct x) as x,
sum(y) as y,
count(z) as z
from sample
where &filter.  /* %put &filter */
group by id;
quit;

%mend;

 

data _null_;
set filter_data;
CALL EXECUTE("%create("||table_name||","||filter||");");
run;

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

Yes. But how do you know what filters to apply when?

andreas_lds
Jade | Level 19

Maybe something like

data filter;
   length source $ 42 filter $ 100;
   infile datalines delimiter='#' dsd;
   input source filter;
   datalines;
sashelp.class#11 <= Age <= 13
;


data _null_;
   set filter;

   call execute(catx(' ', 'proc print data=', source, 'label;'));
   call execute(catx(' ', 'where', filter, ';'));
   call execute('run;');
run;

If you want to create datasets, then you should add a variable to "filter" naming the new dataset.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1228 views
  • 2 likes
  • 3 in conversation