Hi Tom Thanks a lot for taking time and explain this to me in a very easy format. So I have changed the code as per your instructions and it worked.. Code is : %let startdt = 01NOV2016; %let finishdt = 01FEB2017; %let datestamp = %sysfunc(putn("&finishdt"d, yymmn6.)); %macro extract(start,finish); %let enddate = %sysfunc(intnx(month,"&finish."d,0,b),date9.); %let datestamp = %sysfunc(putn("&finishdt"d, yymmn6.)); %let startmonth = "&start."d ; %let endmonth = "&finish."d ; data tk.application_extract_&datestamp.; set sastrain.application_extract; where "&start"d <= datepart(d_entry) <= "&finish"d; run; %mend extract; %extract(&startdt.,&finishdt.); I just need to ask few questions for my understanding and learning. In this code, three variables are defined outside the macro, do we call them global variables as they are defined outside the macro, I think the reason datestamp Variable is defined outside the macro so we can use this datestamp to other codes in the same project whenever we create other files with same datestamp. So that means Startdt and finishdate could be defined inside the macro or do they have to define outside the macro, that’s first question. 2nd question: 04 variables are defined inside the macro, enddate variable is not used anywhere apart from the %put function to see on the log so that can be removed , isn’t it ? Startmonth and endmonth variables in the macro , we use “&start.”d , so the reason was to define the date literal , and we need to dot after the start and it has to be in double quotes. Datestamp , I used the same way as it was outside the macro. We use putn(“&finishdt”d, yymmn6.)).. we use putn with finishdt to change it to numeric format? Is it true? %sysfunction is only used Within macro to able to use putn. 3rd question: When we define the variable we use %let startmonth = "&start."d ; However when we use the where statement , we write as “&start”d , no dot after the start, please advise on that. where "&start"d <= datepart(d_entry) <= "&finish"d; 4th question: If I don’t need start date and only need the finish date so I can extract all data from the finish date , can I write like this: and remove the startmonth variable. %let finishdt = 01FEB2018; %let datestamp = %sysfunc(putn("&finishdt"d, yymmn6.)); %macro extract(finish); %let enddate = %sysfunc(intnx(month,"&finish."d,0,b),date9.); %let datestamp = %sysfunc(putn("&finishdt"d, yymmn6.)); %let endmonth = "&finish."d ; data tk.application_extract_&datestamp.; set sastrain.application_extract; where datepart(d_entry) <= "&finish"d; run; %mend extract; %extract(&finishdt.); question 5: As I have removed the Data _null_ And symputx routines from this code as it was not required. I am just curious when do we require symput routines and why do we use it? And if you suggest any good book or any other source to understand macros , that will be really handy. Please advise. Thanks for your time. TK
... View more