Help using Base SAS procedures

DO loops

Reply
New Contributor
Posts: 3

DO loops

Hi,

I have some programs with multiple steps/procedures that I want to run with a loop. For example, the simplest one is:

data reg_temp;
set hotelJPQ.TueDBA0L1_daily;
where (Week_Code>=1) AND (Week_Code<=4);
run;
PROC reg data=reg_temp outest=reg_out_temp;
* parms b0 b1;
DEMAND: model demand = price;
run;
PROC EXPORT DATA= work.reg_out_temp
OUTFILE= "C:\Research\working papers\Joint price quant\Tue_SAS.xls"
DBMS=Excel;
SHEET="1";
run;
quit;

I would like to replace the numeric values in:
where (Week_Code>=1) AND (Week_Code<=4);
and
SHEET="1";
with a variable (say 'x') within a loop such as
Do x = 1 to 9;

Have tried various approaches including different macros but have had no success.

Is there an easy way (or even a way) of accomplishing this.

Thanks,
lmacdon4
Super Contributor
Super Contributor
Posts: 3,174

Re: DO loops

You may consider the SAS macro language for this type of repetitive processing, where only a subset of "variable information" changes iteratively.

Scott Barry
SBBWorks, Inc.

Recommended Google advanced search arguments, this topic/post:

macro language basics site:sas.com

macro variables introduction site:sas.com Message was edited by: sbb
New Contributor
Posts: 3

Re: DO loops

thanks.

have tried some macros, but still having problems getting the different procs etc to recognize the 'x' variable.
SAS Super FREQ
Posts: 8,868

Re: DO loops

Hi:
This paper serves as an excellent intro to the SAS Macro Facility:
http://www2.sas.com/proceedings/sugi28/056-28.pdf

cynthia
New Contributor
Posts: 3

Re: DO loops

Posted in reply to Cynthia_sas
thanks Cynthia, the above file was very helpful. The macro is working correctly now.

Cheers,
Leo
Ask a Question
Discussion stats
  • 4 replies
  • 154 views
  • 0 likes
  • 3 in conversation