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-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!

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.

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
  • 4 replies
  • 704 views
  • 0 likes
  • 4 in conversation