Below is my code:
libname bvd '/data/bvd';
option ls=180 ps=500;
%macro nn(y); %do;
%macro n(a,b); %do j=1 %to &b;
%if &a=d %then %do;
proc import datafile='/data/bvd/xlsx/20&y_&j.xlsx' out=b&y_&j dbms=xlsx replace;
data &a&y; length BVDID $20. CNAME $50.; set b&y_1-b&y_&j; Source="D";
%end;
%if &a=o %then %do;
proc import datafile='/data/bvd/xlsx/&y_&j.xlsx' out=b&y_&j dbms=xlsx replace;
data &a&y; length BVDID $20. CNAME $50.; set b&y_1-b&y_&j; Source="O";
%end;
data b&y; set d&y o&y; XASSTS=max(ASSTS,SHFU); XREV=max(OPRE,SALE); XEMPL=EMPL; drop ASSTS SHFU OPRE SALE;
%end;
%mend;
%if &y=19 %then %do;
%n(d,7);
%n(o,8);
%end;
%if &y=20 %then %do;
%n(d,11);
%n(o,7);
%end;
%if &y=21 %then %do;
%n(o,14);
%end;
%if &y=22 %then %do;
%n(o,26);
%end;
data temp; set b&y; retain _CNAME; if CNAME ne '' then _CNAME=CNAME; if CNAME eq '' then CNAME=_CNAME; drop _CNAME; proc sort; by CNAME;
data bvd.b&y; set temp; by CNAME; retain _BVDID _XASSTS _XEMPL _SIC1 _SIC2 _XREV;
if not last.CNAME then do; if BVDID ne '' then _BVDID=BVDID; if XASSTS ne . then _XASSTS=XASSTS; if SIC1 ne . then _SIC1=SIC1;
if SIC2 ne . then _SIC2=SIC2; if XEMPL ne . then _XEMPL=XEMPL; if XREV ne . then _XREV=XREV; end;
if not first.CNAME then do; if BVDID eq '' then BVDID= _BVDID; if XASSTS eq . then XASSTS=_XASSTS; if SIC1 eq . then SIC1=_SIC1;
if SIC2 eq . then SIC2=_SIC2; if XEMPL eq . then XEMPL=_XEMPL; if XREV eq . then XREV=_XREV; end; drop _:;
%end;
%mend;
%nn(19);
%nn(20);
%nn(21);
%nn(22);
And this is the error:
51 %nn(19);
WARNING: Apparent symbolic reference Y_ not resolved.
WARNING: Apparent symbolic reference Y_ not resolved.
NOTE 137-205: Line generated by the invoked macro "N".
51 proc import datafile='/data/bvd/xlsx/20&y_&j.xlsx' out=b&y_&j dbms=xlsx replace; data &a&y; length BVDID $20. CNAME $50.; set b&y_1-b&y_&j; Source="D";
_
22
ERROR 22-322: Syntax error, expecting one of the following: ;, (, DATAFILE, DATATABLE, DBMS, DEBUG, FILE, OUT, REPLACE, TABLE, _DEBUG_.
NOTE: Line generated by the invoked macro "N".
51 proc import datafile='/data/bvd/xlsx/20&y_&j.xlsx' out=b&y_&j dbms=xlsx replace; data &a&y; length BVDID $20. CNAME $50.; set b&y_1-b&y_&j; Source="D";
_
200
ERROR 200-322: The symbol is not recognized and will be ignored.
I don't understand why this doesn't work.
My objective is to run the macro nn(y) four times whereby y takes the values 19,20,21,22. The macro nn should activate the macro n(a,b) with set values for a and b for each specific y (So for y=19 the macro n(a,b) should run two times: once where a=d and b=7, and a second time where a=o and b=8). Then the macro nn runs a chunk of code that is the same for all y.
The macro n(a,b) is supposed to import the files which differ in name (some are 2019_X, some are 19_X); this difference is connected to a being equal to "d" or "o". If a=d files to import take the name 2019_X, and if a=o files to import take the name 19_X. Then it should append the two files d and o.
I hope it is clear what I want to do, but if not please ask me for more detail. Thanks in advance for your help.
... View more