When you need to write a macro you first need working code and then you convert it.
Do you have working code that needs to be turned into a macro? And since this is a trivial task why do you need a macro? Which parts are dynamic in nature. Please be more explicit in your questions.
Post the code and describe which part of it should be parameterized.
Use the having clause and the max() summary function in SQL:
proc sql;
select * from dictionary.tables
where libname = 'common'
having crdate = max(crdate);
quit;
Which parts of the code need to be parameterized?
Do you want to change the variable that's used, or do you want to compare with a specific value?
But the max crdate is always used. If the variable name doesn't change that doesn't need to be parametrized.
Post a few different versions of what the code would be for us to understand what you need a macro for.
%macro your_macro_name(memname);
*here comes your code;
*example;
where memname = "&memname";
*further code;
%mend;
Post code, and examples to clarify the question. As for your problem, why do you need a macro?
/* Test data */
proc sql; create table a (a char(2)); quit; data b; b=1; run; /* This is the code */ proc sort data=sashelp.vtable out=inter; by memname; where libname="WORK" and nobs > 0; run; data _null_; set inter (obs=1); call execute(cats('data want; set work.',memname,' (obs=1); run;')); 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 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.
Ready to level-up your skills? Choose your own adventure.