Macro, how to create the aggregate file for each year from monthly output

Reply
Super Contributor
Posts: 420

Macro, how to create the aggregate file for each year from monthly output

Hi Everyone,

I run a Macro for each month of a given period. Each month, there will be an output file, say Number, and I want to include this Number file to a annual file as below:

Data NUMBER_&i;

%if &j=1 %then %do;      *if month=1;

set Number;

%end;

%else %do;

set NUMBER_&i      Number;

%end;

run;

The output of the whole Macro should be: Number_1977, Number_1978 ....

However, with this code, the first iteration (j=1)is not included but after that it work fine.

The ERROR: File Work.NUMBER_1977.DATA does not exist

This notice shows up for all year, at the first month.

Could you please help me with that?

Thank you,

HHC

%macro test (start,end);

    %do i=&start %to &end;

    %do j=3 %to 12 %by 1;

           data year_&j.&i;      set sashelp.workers;

           if month(date)=&j and year(date)=&i then output;  run;

          *ANALYSIS SECTION FOR EACH MONTHLY FILE; there will be 01 summary file per month;

          *Example;

           Proc means noprint;

           var  Electric;

           output out=Number

           N=N;run;

Data NUMBER_&i;

if j=1 %then %do;      *if month=1;

set Number;

%end;

%else %do;

set NUMBER_&i Number;

%end;

run;

   %end;

   %end;

%mend test;

%test (1977,1980);

Super Contributor
Posts: 420

Re: Macro, how to create the aggregate file for each year from monthly output

Oh, I fixed it.

Sorry for the incontinence.

Have a nice weekend.

HHC

Super User
Posts: 11,343

Re: Macro, how to create the aggregate file for each year from monthly output

Hope you meant "inconvenience"!

Ask a Question
Discussion stats
  • 2 replies
  • 205 views
  • 1 like
  • 2 in conversation