Dear community,
I am trying to run the following macro, a lot of errrors result. I
%macro unemp4(ls);
DATA asmt2.gdp3;
set asm2.gdp
L&ls. = LOG(GDP) - LOG (LAG&ls.(GDP));
S&ls. = LAG&ls.(SPREAD);
PROC REG DATA=asmt2.gdp3;
MODEL L&ls.=S&ls./DWPROB;
RUN;
quit;
%MEND unemp4;
%unemp4 (1) %unemp4(2) %unemp4 (3) %unemp4 (4) %unemp4(5) %unemp4 (6)
%unemp4(7) %unemp4 (8)
Thank you for your help!
It would help if you run some of the code with OPTIONS MPRINT; and show the log so we know what type of errors you are getting if syntax errors.
If you are getting unexpected value errors you should provide some example input, the erroneous values and the desired values.
I have attached the log.
What I am trying to do is instead of writing this long code:
DATA asmt2.gdp3;
SET asmt2.gdp;
L1=LOG(GDP)-LOG(LAG1(GDP));
L2=LOG(GDP)-LOG(LAG2(GDP));
L3=LOG(GDP)-LOG(LAG3(GDP));
L4=LOG(GDP)-LOG(LAG4(GDP));
L5=LOG(GDP)-LOG(LAG5(GDP));
L6=LOG(GDP)-LOG(LAG6(GDP));
L7=LOG(GDP)-LOG(LAG7(GDP));
L8=LOG(GDP)-LOG(LAG8(GDP));
S1=LAG1(SPREAD);
S2=LAG2(SPREAD);
S3=LAG3(SPREAD);
S4=LAG4(SPREAD);
S5=LAG5(SPREAD);
S6=LAG6(SPREAD);
S7=LAG7(SPREAD);
S8=LAG8(SPREAD);
RUN;
I am trying to write a macro version:
%macro unemp4(ls);
DATA asmt2.gdp3;
set asm2.gdp
L&ls. = LOG(GDP) - LOG (LAG&ls.(GDP));
S&ls. = LAG&ls.(SPREAD);
RUN;
quit;
%MEND unemp4;
%unemp4 (1) %unemp4(2) %unemp4 (3) %unemp4 (4) %unemp4(5) %unemp4 (6)
%unemp4(7) %unemp4 (8)
Adding the missing semicolon after the SET statement will help a lot, I guess.
Hi,
Well, firstly, what are the errors you get in the log. You have provided no log, nor test data to run this against. Its not quite clear what your macro is attempting to do, or why all the macro code is necessary. Also note that code formatting is quite important to be clearly readble. One important thing to note, which will cause errors is the missing semicolon after each macro call, update as given below. Also, be sure to put options mlogic mprint symbolgen; on before running.
%macro unemp4(ls); data asmt2.gdp3; set asm2.gdp L&ls.=log(gdp) - log (lag&ls.(gdp)); S&ls.=lag&ls.(spread); run; proc reg data=asmt2.gdp3; model l&ls.=s&ls./dwprob; run; quit; %mend unemp4; %unemp4 (1); %unemp4 (2); %unemp4 (3); %unemp4 (4); %unemp4 (5); %unemp4 (6); %unemp4 (7); %unemp4 (8);
Assuming GDP and SPREAD are variables in the dataset i believe error is from use LAG1()-LAG8() functions as these are not valid sas functions.
@Reeza Thanks should have checked before i responded.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.