07-18-2013 11:44 AM
There is a dataset that has date columns from Jul1,2013 to Dec1,2011.
Every week I need to process data taking last 36 weeks starting from the current date.
How to use this in a loop to use in a put statement to output it to a text file alsong with Id .
i.e put @01 id dt_01JUL2013 dt_24JUN2013 dt_17Jun2013?
07-18-2013 04:31 PM
When you are asking:
I have a dataset with varying colum-names (dt_&&date&i) wanting in put statement than:
Define an array in the datastep to process all columns.
The variability of all the dates can be solved by first defining macro variables with the names.
07-18-2013 08:04 PM
That's a bad way to store information, but probably besides the point now.
I think you need to provide more info on your data structure. For example, if it is weekly data the 1st of June is a Saturday, but the 24 is a monday, so how are the columns names determined. I'm assuming you'd need to dynamically generate the columns you'd need to pull. Do you have to do a data step with put or can you use a proc export or tagset to export?
07-18-2013 09:46 PM
I agree with Reeza about your data structure, but anyway, here is how to get what you want, or something close to it :
select name into :keepCols separated by ","
where libname="WORK" and memname="MYTEST" and
input(substr(name,4),? anydtdte9.) >= intnx("WEEK", today(), -36, "S");
create table keep36weeks as
select id, &keepCols from mytest;
07-19-2013 04:03 AM
This assumes that your variables are in a sequential order. I used week.3 because you mentioned the specific dates 01JUL2013 24JUN2013 17JUN2013.
%LET FIRSTMTH = DT_%SYSFUNC(PUTN(%SYSFUNC(INTNX(WEEK.3,%SYSFUNC(TODAY()),-36,END)),DATE9.));
%LET LASTMTH = DT_%SYSFUNC(PUTN(%SYSFUNC(INTNX(WEEK.3,%SYSFUNC(TODAY()),-1,END)),DATE9.));
SET HAVE (KEEP = ID &FIRSTMTH. -- &LASTMTH.);