DATA Step, Macro, Functions and more

Appending daily datasets into a monthly dataset

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 96
Accepted Solution

Appending daily datasets into a monthly dataset

I have a process where I create a daily dataset from a large text file.  At the beginning of the next month I need to append the daily data from the previous month into a monthly dataset.

 

Can this be automated so that I don't have to manually create the monthly dataset.  Can the automation account for leap year and number of days in a month to pick up all files?

 

this is my code now:

 

libname us "/ptr/us_bds/";

 

 

data    us.bds_call_lvl_201802; /* creating the monthly file for all the daily files */

set us.bds_call_lvl_20180201

    us.bds_call_lvl_20180202

    us.bds_call_lvl_20180203

    us.bds_call_lvl_20180204

    us.bds_call_lvl_20180205

    us.bds_call_lvl_20180206

    us.bds_call_lvl_20180207

    us.bds_call_lvl_20180208

    us.bds_call_lvl_20180209

    us.bds_call_lvl_20180210

    us.bds_call_lvl_20180211

    us.bds_call_lvl_20180212

    us.bds_call_lvl_20180213

    us.bds_call_lvl_20180214

    us.bds_call_lvl_20180215

    us.bds_call_lvl_20180216

    us.bds_call_lvl_20180217

    us.bds_call_lvl_20180218

    us.bds_call_lvl_20180219

    us.bds_call_lvl_20180220

    us.bds_call_lvl_20180221

    us.bds_call_lvl_20180222

    us.bds_call_lvl_20180223

    us.bds_call_lvl_20180224

    us.bds_call_lvl_20180225

    us.bds_call_lvl_20180226

    us.bds_call_lvl_20180227

    us.bds_call_lvl_20180228

        ;

run;

 

Thanks, any assistance you can provide will be greatly appreciated.

 

Elliott


Accepted Solutions
Solution
‎03-16-2018 03:40 PM
Super User
Posts: 23,963

Re: Appending daily datasets into a monthly dataset

 

 

You can make a macro variable for the 201802 portion if desired.

untested, note the colon in the data step.

 

%let period = %sysfunc(intnx(month, %sysfunc(today()), -1, b), yymm6.);

data    us.bds_call_lvl_. /* creating the monthly file for all the daily files */

set us.bds_call_lvl_&period.: ;

run;

 

View solution in original post


All Replies
Solution
‎03-16-2018 03:40 PM
Super User
Posts: 23,963

Re: Appending daily datasets into a monthly dataset

 

 

You can make a macro variable for the 201802 portion if desired.

untested, note the colon in the data step.

 

%let period = %sysfunc(intnx(month, %sysfunc(today()), -1, b), yymm6.);

data    us.bds_call_lvl_. /* creating the monthly file for all the daily files */

set us.bds_call_lvl_&period.: ;

run;

 

Frequent Contributor
Posts: 96

Re: Appending daily datasets into a monthly dataset

Thanks!

Frequent Contributor
Posts: 96

Re: Appending daily datasets into a monthly dataset

I tried this but the result comes out to be 18M02.  I have tried to edit 

%let period = %sysfunc(intnx(month, %sysfunc(today()), -1, b), yymm6.);

but have not been able to get the date to come out as YYYYMM format.

 

Thank you

Super User
Posts: 23,963

Re: Appending daily datasets into a monthly dataset

Try yymmN6.

Frequent Contributor
Posts: 96

Re: Appending daily datasets into a monthly dataset

Thanks! I figured that out after I sent the message.


☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 140 views
  • 2 likes
  • 2 in conversation