BookmarkSubscribeRSS Feed
lmacdon4
Calcite | Level 5
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
4 REPLIES 4
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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
lmacdon4
Calcite | Level 5
thanks.

have tried some macros, but still having problems getting the different procs etc to recognize the 'x' variable.
Cynthia_sas
Diamond | Level 26
Hi:
This paper serves as an excellent intro to the SAS Macro Facility:
http://www2.sas.com/proceedings/sugi28/056-28.pdf

cynthia
lmacdon4
Calcite | Level 5
thanks Cynthia, the above file was very helpful. The macro is working correctly now.

Cheers,
Leo

CFC_SAS_Communities_400x225.jpg

Call for content now open!

It's your turn to help shape SAS Innovate 2027. Share your expertise and inspire the SAS community.

Submit your proposal →

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
  • 1795 views
  • 0 likes
  • 3 in conversation