Date variables via computed columns

Reply
Occasional Contributor
Posts: 6

Date variables via computed columns

Hi

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?

thanks

Super User
Posts: 19,815

Re: Date variables via computed columns

Posted in reply to SAS_newbie1

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.

Occasional Contributor
Posts: 6

Re: Date variables via computed columns

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?

Super User
Posts: 5,509

Re: Date variables via computed columns

Posted in reply to SAS_newbie1

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.

Good luck.


Occasional Contributor
Posts: 6

Re: Date variables via computed columns

Posted in reply to Astounding

Thank you, that's very helpful.  Smiley Happy

Super User
Posts: 19,815

Re: Date variables via computed columns

Posted in reply to SAS_newbie1

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.

For example:
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. 

Occasional Contributor
Posts: 6

Re: Date variables via computed columns

Thank you, that's very helpful.  Smiley Happy

Ask a Question
Discussion stats
  • 6 replies
  • 370 views
  • 6 likes
  • 3 in conversation