BookmarkSubscribeRSS Feed
brophymj
Quartz | Level 8

Hi

This isn't working for me. I think the problem is with the "do loop" since when i put the dates into the macro manually it works.

%macro macro1(date);

format live&date. best12.;

live&date. = 0

;

if datchd < &date then do;

     if ddtermd > &date then live&date. = 1;

     if ddtermd = 0 then live&date. = 1;

end;

%mend;

%let start = 20010101

%let end = 20100101

Data Have;

set want;

do i = &start to &end by 10000;

     %macro1(i);

end;

run;

4 REPLIES 4
RamKumar
Fluorite | Level 6

semicolon is missing in following lines.

%let start = 20010101

%let end = 20100101

what you're trying to achieve? Provide some sample data to expand more on your errors.

brophymj
Quartz | Level 8

I hardcodes the code in this forum so left out the semi colons in error. Basically the code should create 11 columns live20010101, live20020101, ..., and so on and they're all populated with 0's unless the dates satisfy the conditions in the macro, uin which case they are populated with 1. The 'do.. by' loop is not working since not even the fields live20010101 ... are being created.

Reeza
Super User

Post some sample input/output. It seems like you're doing something very roundabout to get some results.

Kurt_Bremser
Super User

The do loop is part of the data step and executed at runtime of the data step.

%macro1(i) is executed by the macro processor BEFORE the data step is compiled and executed, with "i" as parameter.

Therefore you end up with the following code in the do loop:

format livei best12.;

livei = 0

;

if datchd < i then do;

     if ddtermd > i then livei = 1;

     if ddtermd = 0 then livei = 1;

end;

Keep in mind that the macro processor is a PREprocessor.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 984 views
  • 0 likes
  • 4 in conversation