Hi @SASKiwi and @qoit
My code now is adjusted a little bit
options mprint;
libname test "C:\Users\pnguyen\Desktop\merge2" access=readonly;
proc contents data=test._ALL_ out=contents;
run;
/*I just change to one country for printing log purpose*/
/*******DROP BDATE**************/
%macro changedate(lib,dsname,var2del);
data _null_;
if 0 then set test.&dsname.;
call symputx('bdate_type',vtype(&var2del));
stop;
run;
data work.&dsname.;
set &test..&dsname.;
%if &bdate_type=C %then %do;
if length(&var2del)=5 and upcase(&var2del) ne 'NA' then
SASDATE = input(&var2del,32.)+'30DEC1899'd ;
else SASDATE= input(&var2del,anydtdte.);
%end;
%else %do;
SASDATE=&var2del;
%end;
format SASDATE yymmdd10.;
if not missing(sasdate) then fir_age = log(1+(2020-year(SASDATE)));
run;
/****macro for BDATE****************/
%mend;
data _null_;
set sashelp.vtable(where=(libname='TEST'));
cmd = catx(',', '%changedate('|| strip(libname), strip(memname), 'BDATE'||');'); put cmd=;
call execute(cmd);
put _N_= memname= ' was submitted to run' ;
run;
The FULL log is
28 options mprint;
29
30 libname test "C:\Users\pnguyen\Desktop\merge2" access=readonly;
NOTE: Libref TEST was successfully assigned as follows:
Engine: V9
Physical Name: C:\Users\pnguyen\Desktop\merge2
31
32 proc contents data=test._ALL_ out=contents;
33 run;
NOTE: The data set WORK.CONTENTS has 138 observations and 41 variables.
NOTE: PROCEDURE CONTENTS used (Total process time):
real time 0.15 seconds
cpu time 0.14 seconds
34 /*I just change to one country for printing log purpose*/
35
36 /*******DROP BDATE**************/
37 %macro changedate(lib,dsname,var2del);
38 data _null_;
39 if 0 then set test.&dsname.;
40 call symputx('bdate_type',vtype(&var2del));
41 stop;
42 run;
43
44 data work.&dsname.;
45 set &test..&dsname.;
46 %if &bdate_type=C %then %do;
2 The SAS System 11:34 Monday, February 15, 2021
47 if length(&var2del)=5 and upcase(&var2del) ne 'NA' then
48 SASDATE = input(&var2del,32.)+'30DEC1899'd ;
49 else SASDATE= input(&var2del,anydtdte.);
50 %end;
51 %else %do;
52 SASDATE=&var2del;
53 %end;
54 format SASDATE yymmdd10.;
55 if not missing(sasdate) then fir_age = log(1+(2020-year(SASDATE)));
56 run;
57
58 /****macro for BDATE****************/
59
60 %mend;
61
62 data _null_;
63 set sashelp.vtable(where=(libname='TEST'));
64 cmd = catx(',', '%changedate('|| strip(libname), strip(memname), 'BDATE'||');'); put cmd=;
65 call execute(cmd);
66 put _N_= memname= ' was submitted to run' ;
67 run;
cmd=%changedate(TEST,ARGENTINA_MERGE2,BDATE);
MPRINT(CHANGEDATE): data _null_;
MPRINT(CHANGEDATE): if 0 then set test.ARGENTINA_MERGE2;
MPRINT(CHANGEDATE): call symputx('bdate_type',vtype(BDATE));
MPRINT(CHANGEDATE): stop;
MPRINT(CHANGEDATE): run;
MPRINT(CHANGEDATE): data work.ARGENTINA_MERGE2;
WARNING: Apparent symbolic reference TEST not resolved.
MPRINT(CHANGEDATE): set &test..ARGENTINA_MERGE2;
MPRINT(CHANGEDATE): SASDATE=BDATE;
MPRINT(CHANGEDATE): format SASDATE yymmdd10.;
MPRINT(CHANGEDATE): if not missing(sasdate) then fir_age = log(1+(2020-year(SASDATE)));
MPRINT(CHANGEDATE): run;
_N_=1 memname=ARGENTINA_MERGE2 was submitted to run
cmd=%changedate(TEST,ZAMBIA_MERGE2,BDATE);
MPRINT(CHANGEDATE): data _null_;
MPRINT(CHANGEDATE): if 0 then set test.ZAMBIA_MERGE2;
MPRINT(CHANGEDATE): call symputx('bdate_type',vtype(BDATE));
MPRINT(CHANGEDATE): stop;
MPRINT(CHANGEDATE): run;
MPRINT(CHANGEDATE): data work.ZAMBIA_MERGE2;
WARNING: Apparent symbolic reference TEST not resolved.
MPRINT(CHANGEDATE): set &test..ZAMBIA_MERGE2;
MPRINT(CHANGEDATE): SASDATE=BDATE;
MPRINT(CHANGEDATE): format SASDATE yymmdd10.;
MPRINT(CHANGEDATE): if not missing(sasdate) then fir_age = log(1+(2020-year(SASDATE)));
MPRINT(CHANGEDATE): run;
_N_=2 memname=ZAMBIA_MERGE2 was submitted to run
NOTE: There were 2 observations read from the data set SASHELP.VTABLE.
WHERE libname='TEST';
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
NOTE: CALL EXECUTE generated line.
3 The SAS System 11:34 Monday, February 15, 2021
1 + data _null_; if 0 then set test.ARGENTINA_MERGE2; call symputx('bdate_type',vtype(BDATE)); stop; run;
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
NOTE: Line generated by the CALL EXECUTE routine.
1 + data
work.ARGENTINA_MERGE2; set &test..ARGENTINA_MERGE2; SASDATE=BDATE; format SASDATE yymmdd10.; if not
_
22
200
1 !+missing(sasdate) then fir_age =
WARNING: Apparent symbolic reference TEST not resolved.
ERROR: File WORK.RGENTINA_MERGE2.DATA does not exist.
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, ;, CUROBS, END, INDSNAME, KEY, KEYRESET, KEYS,
NOBS, OPEN, POINT, _DATA_, _LAST_, _NULL_.
ERROR 200-322: The symbol is not recognized and will be ignored.
2 + log(1+(2020-year(SASDATE))); run;
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.ARGENTINA_MERGE2 may be incomplete. When this step was stopped there were 0 observations and 3
variables.
WARNING: Data set WORK.ARGENTINA_MERGE2 was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.01 seconds
2 + ;
3 + data _null_; if 0 then set test.ZAMBIA_MERGE2; call symputx('bdate_type',vtype(BDATE)); stop; run;
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
NOTE: Line generated by the CALL EXECUTE routine.
3 + data
work.ZAMBIA_MERGE2; set &test..ZAMBIA_MERGE2; SASDATE=BDATE; format SASDATE yymmdd10.; if not
_
22
200
3 !+missing(sasdate) then fir_age = log(1+
WARNING: Apparent symbolic reference TEST not resolved.
ERROR: File WORK.AMBIA_MERGE2.DATA does not exist.
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, ;, CUROBS, END, INDSNAME, KEY, KEYRESET, KEYS,
NOBS, OPEN, POINT, _DATA_, _LAST_, _NULL_.
4 The SAS System 11:34 Monday, February 15, 2021
ERROR 200-322: The symbol is not recognized and will be ignored.
4 +(2020-year(SASDATE))); run;
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.ZAMBIA_MERGE2 may be incomplete. When this step was stopped there were 0 observations and 3 variables.
WARNING: Data set WORK.ZAMBIA_MERGE2 was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
4 + ;
68
69 %LET _CLIENTTASKLABEL=;
70 %LET _CLIENTPROCESSFLOWNAME=;
71 %LET _CLIENTPROJECTPATH=;
72 %LET _CLIENTPROJECTPATHHOST=;
73 %LET _CLIENTPROJECTNAME=;
74 %LET _SASPROGRAMFILE=;
75 %LET _SASPROGRAMFILEHOST=;
76
77 ;*';*";*/;quit;run;
78 ODS _ALL_ CLOSE;
79
80
81 QUIT; RUN;
Could you please give me a hint to deal with such a problem?
Many thanks and warm regards.
... View more