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

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1250 views
  • 2 likes
  • 3 in conversation