my control dataset named datanames with 5 variables as follows: memtype libname memname sic state DATA WORK AL61 61 AL DATA WORK AL62 62 AL DATA WORK AL71 71 AL DATA WORK AL81 81 AL DATA WORK AL91 91 AL DATA WORK AK61 61 AK DATA WORK AK62 62 AK DATA WORK AK71 71 AK DATA WORK AK81 81 AK DATA WORK AK91 91 AK DATA WORK KY61 61 KY DATA WORK KY62 62 KY DATA WORK KY71 71 KY DATA WORK NM61 61 NM DATA WORK NM62 62 NM DATA WORK NM71 71 NM DATA WORK NM81 81 NM DATA WORK NM91 91 NM variables memname, state and sic are all character variables; my original sas datasets imported from excel do not include the two variables: state and sic but the names of datasets contain the information:the first two letters are state initials and the digits followed are sic codes. Now I want to add the two variables to the sas datasets. with state as character variable and sic as numeric. My macro program and call excute codes are as follows: %macro addvar(state,sic); data &state&sic; length state $ 2.; set &state&sic; state="&state"; code=input("&sic",8.) run; %mend addvar; data _null_; set datanames; call symput('state',state); call symput('sic',sic); call execute(cats('%nrstr(%addvar)(',state,sic,')')); run; When I run the above codes, I got the variable state with values the same as the variable memname, and code with values missing. I don't know why? The above are my original post. Later with Tom's suggestion, I changed my codes to as follows: 1. With sic as numeric variable 1. With sic as numeric variable 1. With sic as numeric variable options mprint; %macro addvar1(state,sic); data &state&sic; length state $ 4. code 8.; /*why I length state to $ 4. is to avoid false result being concealed.*/ set &state&sic; state="&state"; code=&sic; run; %mend addvar1; data _null_; set datanames; call execute(cats('%nrstr(%addvar1)(',state,sic,')')); run; After running the codes, I got the following messeges(I choose the first three sic number to save space): NOTE: There were 8 observations read from the data set WORK.DATANAMES. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds NOTE: CALL EXECUTE generated line. SYMBOLGEN: Macro variable STATE resolves to AL61 SYMBOLGEN: Macro variable SIC resolves to 1 + %addvar1(AL61) MPRINT(ADDVAR1): data AL61; MPRINT(ADDVAR1): length state $ 4. code 8.; SYMBOLGEN: Macro variable STATE resolves to AL61 SYMBOLGEN: Macro variable SIC resolves to MPRINT(ADDVAR1): set AL61; SYMBOLGEN: Macro variable STATE resolves to AL61 NOTE 137-205: Line generated by the invoked macro "ADDVAR1". 1 data &state&sic; length state $ 4. code 8.; set &state&sic; 1 ! state="&state"; sic=&sic; run; - 22 ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant, a datetime constant, a missing value, INPUT, PUT. MPRINT(ADDVAR1): state="AL61"; SYMBOLGEN: Macro variable SIC resolves to MPRINT(ADDVAR1): sic=; MPRINT(ADDVAR1): run; NOTE: The SAS System stopped processing this step because of errors. WARNING: The data set WORK.AL61 may be incomplete. When this step was stopped there were 0 observations and 101 variables. WARNING: Data set WORK.AL61 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 SYMBOLGEN: Macro variable STATE resolves to AL62 SYMBOLGEN: Macro variable SIC resolves to 2 + %addvar1(AL62) MPRINT(ADDVAR1): data AL62; MPRINT(ADDVAR1): length state $ 4. code 8.; SYMBOLGEN: Macro variable STATE resolves to AL62 SYMBOLGEN: Macro variable SIC resolves to MPRINT(ADDVAR1): set AL62; SYMBOLGEN: Macro variable STATE resolves to AL62 NOTE 137-205: Line generated by the invoked macro "ADDVAR1". 1 data &state&sic; length state $ 4. code 8.; set &state&sic; 1 ! state="&state"; sic=&sic; run; - 22 ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant, a datetime constant, a missing value, INPUT, PUT. MPRINT(ADDVAR1): state="AL62"; SYMBOLGEN: Macro variable SIC resolves to MPRINT(ADDVAR1): sic=; MPRINT(ADDVAR1): run; NOTE: The SAS System stopped processing this step because of errors. WARNING: The data set WORK.AL62 may be incomplete. When this step was stopped there were 0 observations and 101 variables. WARNING: Data set WORK.AL62 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 SYMBOLGEN: Macro variable STATE resolves to AL69 SYMBOLGEN: Macro variable SIC resolves to 3 + %addvar1(AL69) MPRINT(ADDVAR1): data AL69; MPRINT(ADDVAR1): length state $ 4. code 8.; SYMBOLGEN: Macro variable STATE resolves to AL69 SYMBOLGEN: Macro variable SIC resolves to MPRINT(ADDVAR1): set AL69; SYMBOLGEN: Macro variable STATE resolves to AL69 NOTE 137-205: Line generated by the invoked macro "ADDVAR1". 1 data &state&sic; length state $ 4. code 8.; set &state&sic; 1 ! state="&state"; sic=&sic; run; - 22 ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant, a datetime constant, a missing value, INPUT, PUT. MPRINT(ADDVAR1): state="AL69"; SYMBOLGEN: Macro variable SIC resolves to MPRINT(ADDVAR1): sic=; MPRINT(ADDVAR1): run; NOTE: The SAS System stopped processing this step because of errors. WARNING: The data set WORK.AL69 may be incomplete. When this step was stopped there were 0 observations and 101 variables. WARNING: Data set WORK.AL69 was not replaced because this step was stopped. NOTE: DATA statement used (Total process time): real time 0.01 seconds cpu time 0.00 seconds 2. With sic1 as character variable /*I created sic1 to be character variable with the put function*/ 2. With sic1 as character variable 2. With sic1 as character variable options mprint; %macro addvar(state,sic1); data &state&sic1; length state $ 4. code 8.; set &state&sic1; state="&state"; code=input("&sic1",8.); run; %mend addvar; data _null_; set datanames; call execute(cats('%nrstr(%addvar)(',state,sic1,')')); run; This time without warning messages, but I got the variable state with values the same as the variable memname, and code with values missing. just the same as my last post, and I could not find the reason. the mprint option provided the following: NOTE: There were 8 observations read from the data set WORK.DATANAMES. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds NOTE: CALL EXECUTE generated line. SYMBOLGEN: Macro variable STATE resolves to AL61 SYMBOLGEN: Macro variable SIC1 resolves to 1 + %addvar(AL61) MPRINT(ADDVAR): data AL61; MPRINT(ADDVAR): length state $ 4. code 8.; SYMBOLGEN: Macro variable STATE resolves to AL61 SYMBOLGEN: Macro variable SIC1 resolves to MPRINT(ADDVAR): set AL61; SYMBOLGEN: Macro variable STATE resolves to AL61 MPRINT(ADDVAR): state="AL61"; SYMBOLGEN: Macro variable SIC1 resolves to MPRINT(ADDVAR): code=input("",8.); MPRINT(ADDVAR): run; NOTE: There were 13 observations read from the data set WORK.AL61. NOTE: The data set WORK.AL61 has 13 observations and 100 variables. NOTE: DATA statement used (Total process time): real time 0.01 seconds cpu time 0.00 seconds SYMBOLGEN: Macro variable STATE resolves to AL62 SYMBOLGEN: Macro variable SIC1 resolves to 2 + %addvar(AL62) MPRINT(ADDVAR): data AL62; MPRINT(ADDVAR): length state $ 4. code 8.; SYMBOLGEN: Macro variable STATE resolves to AL62 SYMBOLGEN: Macro variable SIC1 resolves to MPRINT(ADDVAR): set AL62; SYMBOLGEN: Macro variable STATE resolves to AL62 MPRINT(ADDVAR): state="AL62"; SYMBOLGEN: Macro variable SIC1 resolves to MPRINT(ADDVAR): code=input("",8.); MPRINT(ADDVAR): run; NOTE: There were 13 observations read from the data set WORK.AL62. NOTE: The data set WORK.AL62 has 13 observations and 100 variables. NOTE: DATA statement used (Total process time): real time 0.01 seconds cpu time 0.00 seconds SYMBOLGEN: Macro variable STATE resolves to AL69 SYMBOLGEN: Macro variable SIC1 resolves to 3 + %addvar(AL69) MPRINT(ADDVAR): data AL69; MPRINT(ADDVAR): length state $ 4. code 8.; SYMBOLGEN: Macro variable STATE resolves to AL69 SYMBOLGEN: Macro variable SIC1 resolves to MPRINT(ADDVAR): set AL69; SYMBOLGEN: Macro variable STATE resolves to AL69 MPRINT(ADDVAR): state="AL69"; SYMBOLGEN: Macro variable SIC1 resolves to MPRINT(ADDVAR): code=input("",8.); MPRINT(ADDVAR): run; NOTE: There were 13 observations read from the data set WORK.AL69. NOTE: The data set WORK.AL69 has 13 observations and 100 variables. NOTE: DATA statement used (Total process time): real time 0.01 seconds cpu time 0.01 seconds SYMBOLGEN: Macro variable STATE resolves to AL71 SYMBOLGEN: Macro variable SIC1 resolves to 4 + %addvar(AL71) MPRINT(ADDVAR): data AL71; MPRINT(ADDVAR): length state $ 4. code 8.; SYMBOLGEN: Macro variable STATE resolves to AL71 SYMBOLGEN: Macro variable SIC1 resolves to MPRINT(ADDVAR): set AL71; SYMBOLGEN: Macro variable STATE resolves to AL71 MPRINT(ADDVAR): state="AL71"; SYMBOLGEN: Macro variable SIC1 resolves to MPRINT(ADDVAR): code=input("",8.); MPRINT(ADDVAR): run; NOTE: There were 13 observations read from the data set WORK.AL71. NOTE: The data set WORK.AL71 has 13 observations and 100 variables. NOTE: DATA statement used (Total process time): real time 0.01 seconds cpu time 0.00 seconds SYMBOLGEN: Macro variable STATE resolves to AL79 SYMBOLGEN: Macro variable SIC1 resolves to 5 + %addvar(AL79) MPRINT(ADDVAR): data AL79; MPRINT(ADDVAR): length state $ 4. code 8.; SYMBOLGEN: Macro variable STATE resolves to AL79 SYMBOLGEN: Macro variable SIC1 resolves to MPRINT(ADDVAR): set AL79; SYMBOLGEN: Macro variable STATE resolves to AL79 MPRINT(ADDVAR): state="AL79"; SYMBOLGEN: Macro variable SIC1 resolves to MPRINT(ADDVAR): code=input("",8.); MPRINT(ADDVAR): run; NOTE: There were 13 observations read from the data set WORK.AL79. NOTE: The data set WORK.AL79 has 13 observations and 100 variables. NOTE: DATA statement used (Total process time): real time 0.01 seconds cpu time 0.01 seconds SYMBOLGEN: Macro variable STATE resolves to AL81 SYMBOLGEN: Macro variable SIC1 resolves to 6 + %addvar(AL81) MPRINT(ADDVAR): data AL81; MPRINT(ADDVAR): length state $ 4. code 8.; SYMBOLGEN: Macro variable STATE resolves to AL81 SYMBOLGEN: Macro variable SIC1 resolves to MPRINT(ADDVAR): set AL81; SYMBOLGEN: Macro variable STATE resolves to AL81 MPRINT(ADDVAR): state="AL81"; SYMBOLGEN: Macro variable SIC1 resolves to MPRINT(ADDVAR): code=input("",8.); MPRINT(ADDVAR): run; NOTE: There were 13 observations read from the data set WORK.AL81. NOTE: The data set WORK.AL81 has 13 observations and 100 variables. NOTE: DATA statement used (Total process time): real time 0.01 seconds cpu time 0.01 seconds SYMBOLGEN: Macro variable STATE resolves to AL89 SYMBOLGEN: Macro variable SIC1 resolves to 7 + %addvar(AL89) MPRINT(ADDVAR): data AL89; MPRINT(ADDVAR): length state $ 4. code 8.; SYMBOLGEN: Macro variable STATE resolves to AL89 SYMBOLGEN: Macro variable SIC1 resolves to MPRINT(ADDVAR): set AL89; SYMBOLGEN: Macro variable STATE resolves to AL89 MPRINT(ADDVAR): state="AL89"; SYMBOLGEN: Macro variable SIC1 resolves to MPRINT(ADDVAR): code=input("",8.); MPRINT(ADDVAR): run; NOTE: There were 13 observations read from the data set WORK.AL89. NOTE: The data set WORK.AL89 has 13 observations and 100 variables. NOTE: DATA statement used (Total process time): real time 0.01 seconds cpu time 0.01 seconds SYMBOLGEN: Macro variable STATE resolves to AL91 SYMBOLGEN: Macro variable SIC1 resolves to 8 + %addvar(AL91) MPRINT(ADDVAR): data AL91; MPRINT(ADDVAR): length state $ 4. code 8.; SYMBOLGEN: Macro variable STATE resolves to AL91 SYMBOLGEN: Macro variable SIC1 resolves to MPRINT(ADDVAR): set AL91; SYMBOLGEN: Macro variable STATE resolves to AL91 MPRINT(ADDVAR): state="AL91"; SYMBOLGEN: Macro variable SIC1 resolves to MPRINT(ADDVAR): code=input("",8.); MPRINT(ADDVAR): run; NOTE: There were 13 observations read from the data set WORK.AL91. NOTE: The data set WORK.AL91 has 13 observations and 100 variables. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.01 seconds