11-12-2013 04:17 PM
I'm new to SAS and am using SAS EPG. I have a project that produces several outputs based on dates between first of the month and last of the month for the previous month. This will eventually be changed to first of the quarter and last of the quarter.
I have hard coded the dates to get the project running, and now I need to change the dates to variables. I'm finding SAS dates quite confusing and am not sure how to write this - I think somehow via computed columns? Can anyone help?
11-12-2013 04:24 PM
I think you want to get into prompts and macro variables instead.
However, you need to provide more details as to how your data is structured and what you're trying to do.
I'm assuming the EPG is Enterprise Guide by the way. Generally, if you have EG questions you should post in that specific forum to get better responses.
11-12-2013 04:59 PM
Yes, it's referred to as EPG here but it is Enterprise Guide.
I want to automate the programme to run automatically each month (and later each quarter) - don't prompts require user interaction?
11-12-2013 05:13 PM
A commonly used combination is the current date plus the INTNX function. For example:
begin = intnx('month', "&sysdate9"d, -1);
end = intnx('month', "&sysdate9"d, 0);
Then subset using:
begin <= datevar < end
BEGIN will be the first day of the previous month, and END will be the first day of the current month. INTNX supports various time periods, including QUARTER.
So this doesn't schedule the program to run, but it does automatically select the previous month's data whenever the program does run.
11-12-2013 05:16 PM
Prompts do, macro variables don't, prompts are an interactive way of selecting macro variables.
You can look at the &sysdate. that will give the current date.
Then you can look at the intck or intnx functions to get you the dates you need for your queries.
Start of the month:
intnx('month', "&sysdate."d, 0, 'b')
End of the month:
intnx('month', "&sysdate."d, 0, 'e')
Switch month to quarter to get start/end of quarter.