LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (January 2005, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Mon, 3 Jan 2005 09:30:24 -0800
Reply-To:     Dennis Diskin <diskin@SNET.NET>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Dennis Diskin <diskin@SNET.NET>
Subject:      Re: Seemingly invalid macro DO loop constructs
Comments: To: Michael Murff <mjm33@MSM1.BYU.EDU>
In-Reply-To:  <s1d91ba3.022@Msm1.byu.edu>
Content-Type: text/plain; charset=us-ascii

Michael,

Although SAS and SAS Macro are similar, thay are NOT the same. There are a number of contructs in SAS which do not wrk in macro and you have found one. One of several possibilities is to create a macro variable holding the set of iterations you want which is then used in the %do loop via a scan.

%let _jlsit = 7 8 9 10 11 12 1 2 3 4 5 6; %do _j = 1 %to 12; %let j = %scan(&_jlist,&_j,%str( )); %put &j; %end;

HTH, Dennis Diskin

Michael Murff <mjm33@MSM1.BYU.EDU> wrote: Hi SAS gurus,

I frequently have cause to structure do loop indexes as shown in the functional datastep code example below. To my chagrin these DO constructs do not seem to be valid in macro syntax. Could someone advise me on a workaround? I need to nest a large section of code in a macro DO loop and would rather not have to create two copies of the code with the only difference being the index sequence.

Many thanks,

Michael Murff Provo, UT

/*Very useful datastep DO constructs */ *********************************************************; data _null_; /* a useful D0 construct */ do i=7 to 12, 1 to 6; put i; end;

/* another useful D0 construct */ do j=7,8,9,10,11,12,1,2,3,4,5,6; put j; end; run;

*********************************************************;

/* Apparently invalid macro syntax */ *********************************************************;

%macro testdo1; /* apparently not available in macro syntax */ %do i=7 %to 12, 1 %to 6; %put &i; %end; %mend;

%testdo1

%macro testdo2; /* apparently not available in macro syntax */ %do j=7,8,9,10,11,12,1,2,3,4,5,6; %put &j; %end; %mend;

%testdo2

*********************************************************;


Back to: Top of message | Previous page | Main SAS-L page