Desktop productivity for business analysts and programmers

Create data table of dates based on todays date

Reply
Contributor
Posts: 23

Create data table of dates based on todays date

Hi - sorry very new to SAS & EG - I am trying to create a list of dates that I can then use further on as parameters in a drop down box. I know how to do the latter but I cant figure out how to create a variable with a list of dates.

So for example using:

data test;
date_today = today();
CurMonth = month (date_today) ;
CurYear = year (date_today) ;
lstMonth = MDY(CurMonth-1, 1, Curyear) ;
NxtMonth = MDY(CurMonth+1, 1, Curyear) ;
format date_today mmddyy10. ;
format lstmonth mmddyy10. ;
format NxtMonth mmddyy10. ;
run;

So my question is that given I have established a list of dates, CurMonth, lstmonth and Nxtmnth - how do I put these into a data table under a variable name 'Mnth_List'
SAS Employee
Posts: 149

Re: Create data table of dates based on todays date

So, it sounds like you're good to go on setting up the parameter the way you want. I think you're asking how to transform a data set with one row and five columns into a data set with five rows and one column. Is that correct?

CurMonth CurYear lstMonth NxtMonth
5 2010 04/01/2010 06/01/2010

If you want to get five rows and one column (well, two columns really, but just one column with the values in question), I would use a stack columns task. Drag all the variables into the Columns to Stack role. The only problem with this is it will not preserve the formatting on the dates. If you wanted to go that route, I'd make all the columns character in the code you supplied via PUT functions (example: date_today=put(today(),mmddyy10.) ). Note that the Stack Columns task does require all character or all numeric columns in what it can stack.

FYI, if you're using EG 4.2 you should check out the Date and Date Range prompt types... those may have the functionality you're after here with Today, Current Day of Next Month, etc.
Ask a Question
Discussion stats
  • 1 reply
  • 1037 views
  • 0 likes
  • 2 in conversation