Gday,
I have a small query about why a macro variable would behave differently in the following example:
I have an include statement after this and it runs differently, depending on which of the first two dte_end values I use. I have set it up like this because sometimes I want the included job to be run on a monthly basis or a daily basis.
I think the second dte_end variable works as expected, it's the first one that doesn't. I was wondering if there was a good reason for this?
I'm running SAS 9.3
Thanks
SAS dates are defined as then number of days being passed since 1jan1960 SAS(R) 9.4 Language Reference: Concepts, Fourth Edition
The first construct is calculating those and storing those in wp1dstr wp1dend as numbers exactly as of your instructions.
Adding the conversion to those numbers to be displayed as text is a chosen date format.
When using SAS datasets the test on dates with a number is no issue as it is still SAS.
When you put those numbers inside strings you are mixing up things.
When you want to use external datasets / databases that number is an issue as they are not SAS. The text date will do, but the SAS text date will not.
Having all thos in one let statement it would be like:
%let dte_str = %sysfunc(putn( %sysfunc(intnx(week, %sysfunc(today()), -1, b ) ) , date9.)) ;
%let dte_end= %sysfunc(putn( %sysfunc(intnx(week, %sysfunc(today()), -1, e ) ) , date9.)) ;
In planning situations (scheduling) and testing it is often more practical not to use the system-date today but one that can be set as an alternate day
For that some local standard being setup and to be followed will solve a lot of those date issues.
Sorry, am not clear on your question. In the second two examples you have provided you put the text of a date into a string which contains quotes around it (single or double) and finish it with a d to indicate a date. In the first example you resolve the function out to be a number, which is what dates are really in background. So both 20189 and "11Apr2015"d are the same thing, just displayed differently.
Secondly, why use macro variables to deal with dates? Macro variables are text data which are used much like a find/replace command. Dates are numeric data. You can shoehorn one into the other bu putting dates, and input results, but you will just end up with messy code which is hard to debug. Put you date paramters in a dataset, then you can use merging to use that with your code, and you have full functionality of date processing within a datastep, e.g.
proc sql;
create table WANT as
select A.JOB_ID,
A.JOB_DATE
from JOBS A
where A.JOB_DATE < (select ACTION_DATE from PARAMETER_TABLE);
quit;
SAS dates are defined as then number of days being passed since 1jan1960 SAS(R) 9.4 Language Reference: Concepts, Fourth Edition
The first construct is calculating those and storing those in wp1dstr wp1dend as numbers exactly as of your instructions.
Adding the conversion to those numbers to be displayed as text is a chosen date format.
When using SAS datasets the test on dates with a number is no issue as it is still SAS.
When you put those numbers inside strings you are mixing up things.
When you want to use external datasets / databases that number is an issue as they are not SAS. The text date will do, but the SAS text date will not.
Having all thos in one let statement it would be like:
%let dte_str = %sysfunc(putn( %sysfunc(intnx(week, %sysfunc(today()), -1, b ) ) , date9.)) ;
%let dte_end= %sysfunc(putn( %sysfunc(intnx(week, %sysfunc(today()), -1, e ) ) , date9.)) ;
In planning situations (scheduling) and testing it is often more practical not to use the system-date today but one that can be set as an alternate day
For that some local standard being setup and to be followed will solve a lot of those date issues.
Thanks for the response.
Honestly I'm not sure if your response is correct, I'm not doing a text/string comparison. It sounds reasonable though.
I'll be sure to try your suggested code, but am not sure if that's how I want my jobs to run.
Think on how you want your jobs to be run. What times automated handed over to others etc.
At one time I did set a standard for users offering al lot of those macro-vars (current week last week, current mont lat month as all kind) in macro text-string with a simulation date for time-travelling.
That is very advanced and may not according your needs.
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 how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.