Help using Base SAS procedures

Do by loops

Reply
Super Contributor
Posts: 259

Do by loops

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;

Regular Contributor
Posts: 168

Re: Do by loops

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.

Super Contributor
Posts: 259

Re: Do by loops

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.

Super User
Posts: 17,840

Re: Do by loops

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

Super User
Posts: 6,940

Re: Do by loops

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.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Ask a Question
Discussion stats
  • 4 replies
  • 197 views
  • 0 likes
  • 4 in conversation