Days alone are not sufficient to cover your situation, since you can't correctly calculate the flowovers between months.
How are the datasets named after day 4?
Will the datasets, that aren't needed for appending any more, be deleted?
Is there a variable in the datasets to identify the day of creation/import?
It is almost always a bad idea to dates, years or such information in dataset names, processing data will be easier if such information is stored in variables.
@thanikondharish wrote:
Day 4:Ex_31
Day 5:Ex_1.........
And from where do you know that the previous month had 31 days without knowing the exact month?
@thanikondharish wrote:
If all are 31 days months
Interesting concept ... you will have to give us some more examples, especially explaining what should happen when month changes.
@thanikondharish wrote:
If all are 31 days months
Which calendar are you using? Mine has several months with 30 days, and one with 28 or 29 ...
Is there any way you can rename your datasets from this poorly designed naming convention to ex_yyyymmdd, for example ex_20190730, ex_20190731, ex_20190801, ...., ex_20200101, etc.? It will make your life much easier.
Since you haven't been forthcoming with requested details, I can only give you code to compute the dataset names for three days past:
data _null_;
length ds_string $100;
do date = today() - 2 to today();
ds_string = catx(' ',ds_string,'ex_' !! put(date,yymmddn8.));
end;
call symputx('ds_string',ds_string);
run;
data want;
set &ds_string.;
run;
Your original requirements:
My query is how append every 3 days like
1st day:
Ex_28.
2nd day:
Append. Ex_28 Ex_29
3rd day:
Append Ex_28 Ex_29 Ex_30
4th day:
Append Ex_29 Ex_30 Ex_31
On 4th day we have to avoid first day data set
The solution:
data _null_;
length ds_string $100;
do date = today() - 2 to today();
ds_string = catx(' ',ds_string,'ex_' !! put(date,yymmddn8.));
end;
call symputx('ds_string',ds_string);
run;
data want;
set &ds_string.;
run;
Thanq it's working
How is this "working"? Your requirements were to return one dataset on day 1, two datasets on day 2, 3 datasets on day 3, then a rolling 3 datasets backwards from day 4 onward. The solution doesn't do that. And you say that you only append every three days, not every day per the solution.
You need to learn to ask a better question if you expect a better answer (and in less than two pages and 13 posts).
@thanikondharish wrote:
My query is how append every 3 days like
1st day:
Ex_28.
2nd day:
Append. Ex_28 Ex_29
3rd day:
Append Ex_28 Ex_29 Ex_30
4th day:
Append Ex_29 Ex_30 Ex_31
On 4th day we have to avoid first day data set
You say append. Do you mean concatenate instead? If you're appending, wouldn't you just append to the base table each day? Or are you wanting a rolling three days?
I started with this, but I'm bailing out. I don't know exactly what you want to do.
* create some dummy datasets ;
data dates;
do date="01JUL2019"d to "31JUL2019"d;
output;
end;
format date yymmddn8.;
run;
proc sql noprint;
select date into :dates separated by " " from dates;
quit;
%macro code;
data ex_&word;
chr_date="&word"; * dummy data ;
run;
%mend;
%loop(&dates)
* initialize audit log ;
data auditlog;
length rundate startdate enddate 8;
format rundate date9. startdate enddate yymmddn.;
rundate = today();
startdate = today();
enddate = today();
run;
proc sql;
select
intnx('day',max_enddate,1) as startdate format=yymmddn.
,intnx('day',max_enddate,3) as startdate format=yymmddn.
into
:startdate,:enddate
from (
select
max(enddate) as max_enddate
from
auditlog
)
;
quit;
%put &=startdate &=enddate;
* loop over the dates, append the source tables, and write a row to the audit log. ;
You don't explain what logic determines 1st day, 2nd day, 3rd day.
Maybe you can run with this code and make something work.
At this point I'm guessing at the details of what you want to do, and why you want to do it.
Perhaps get a colleague to help you better ask your question?
See https://github.com/scottbass/SAS/blob/master/Macro/loop.sas for the %loop macro.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.