BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
whijazi
Calcite | Level 5

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
You're overwriting your data set with each call. So the first call creates data set gdp3 and then the second call creates a new gdp3 data set, with the source data gdp and everything from the first step is forgotten. You may want to look into a macro loop in your data step instead of multiple calls, as well as a way to store your final data set.

View solution in original post

11 REPLIES 11
ballardw
Super User

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.

whijazi
Calcite | Level 5

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)

FreelanceReinh
Jade | Level 19

Adding the missing semicolon after the SET statement will help a lot, I guess.

Reeza
Super User
You're overwriting your data set with each call. So the first call creates data set gdp3 and then the second call creates a new gdp3 data set, with the source data gdp and everything from the first step is forgotten. You may want to look into a macro loop in your data step instead of multiple calls, as well as a way to store your final data set.
whijazi
Calcite | Level 5
Thanks, I see the issue. I will try a DO loop
Reeza
Super User
If you have proc expand, or a SAS/ETS license this is also a lot easier to calculate. It's worth looking into.
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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);

 

ndp
Quartz | Level 8 ndp
Quartz | Level 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.

ndp
Quartz | Level 8 ndp
Quartz | Level 8

@Reeza Thanks should have checked before i responded.

whijazi
Calcite | Level 5
Thanks for your help ndp

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 11 replies
  • 1876 views
  • 1 like
  • 6 in conversation