date check

Reply
Contributor
Posts: 29

date check

okay, so i need to, as a part of a larger process, check if the date in a field (MONTH) has last months date in it.  if it does it needs to run a series of queries and if it does not, then run other queries.   i am just missing how to figure this out.  i assume to do it, it needs to be run from a macro so something like...

 

%macro datecheck;

%local qry mnthck

%let qry=(proc sql; select max(MONTH) as MNTH from TABLE; quitSmiley Wink;

%let today=%sysfunc(today());

%let lmnth=%sysfunc(intnx(month,&today,-1));

%if &lmnth=&qry %then

%do;

 

list of queries to run...

 

%end;

%mend datecheck;

run;

 

any help?  obviously that does not work but i am also not far off from getting the right answer.  i am just missing the part of getting the query results. 

Super User
Posts: 10,215

Re: date check

proc sql noprint;
select max(month) into :mnth from table;
quit;

%macro datecheck;
%if %sysfunc(intnx(month,&mnth,0,b)) = %sysfunc(intnx(month,%sysfunc(today()),-1,b))
%then %do; /* last month */
/* some queries */
%end;
%else %do; /* other month */
/* some other queries */
%end;
%mend;
%datecheck
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Ask a Question
Discussion stats
  • 1 reply
  • 91 views
  • 0 likes
  • 2 in conversation