Your CALL EXECUTE is incorrectly specified. You have:
data _null_;
set datanames;
call execute(cats('%nrstr(%addvar)(',state,sic1,')'));
run
you need to include a comma between the resolved values of state and sic1. In part:
,state , ',' , sic1, without the comma state and sic1 are being appended and passed to the first parameter which is state.
Post test data in the form of a datastep in a code window (its the {i} above post area).
For your issue, you do not need to do any of that. Assume you have three datasets of AC_123, DE_345, WE_111, then you can extract this information, and put them all in one dataset simply by:
data want; set ac_123 de_345 we_111 indsname=tmp; state=scan(tmp,1,"_"); sic=scan(tmp,2,"_"); run;
I would assume that it is is because you passed a missing value for the second parameter for your macro calls.We would need to see the actual dataset you ran and/or the generated macro calls. Perhaps like the datasets you are generating you called that variable CODE instead of SIC?
Note that there is no need to add quotes to numeric literals in the generated assignment statement in your macro.
%macro addvar(state,sic);
data &state&sic;
length state $2 code 8;
set &state&sic;
state="&state";
code=&sic ;
run;
%mend addvar;
Also why did you create macro variables that you did not need?
data _null_;
set datanames;
call execute(cats('%nrstr(%addvar)(',state,sic,')'));
run;
Looks like your macro has errors. Turn on the MPRINT option so that you can see the lines of code that the macro call generates. That should help debug the macro.
@owenwqp1 wrote:
@Tom Thank you so much Tom! With the sample codes you gave me in answering my last post, I sucessfully solved the problem of importing excel tables and changing the charater variables into numeric. That saved me a lot of typing work, since I have more than 6000 excel tables of sic3 indutries and later more than 6000 sas datasets and each with around 100 variables. The original data tables in excel were named with the state name together with the sic3 codes(eg. Florida101,Texas201, NewMexico361, Massachusetts311 etc.). Since the state name and sic3 code are included in the excel table names, they are not included as variables in the original excel tables. What I want is to add the state names and sic3 code as two variables to each sas dataset. The codes I posted yesterday is to deal with this problem. I submitted the code you provided me, but sas gives the following error message: 1 + %addvar(FlORIDA101) 22: LINE and COLUMN cannot be determined.; 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. What's wrong?
Did you misspell Florida? Or do you have a dataset named incorrectly?
Notice that &state contains both the state and sic codes and that &SIC is null. take a look at your code that reads the control file and builds these two variables. make sure that both are correct at that step. Try %PUT &=STATE &=SIC1;
Your CALL EXECUTE is incorrectly specified. You have:
data _null_;
set datanames;
call execute(cats('%nrstr(%addvar)(',state,sic1,')'));
run
you need to include a comma between the resolved values of state and sic1. In part:
,state , ',' , sic1, without the comma state and sic1 are being appended and passed to the first parameter which is state.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.