| Date: | Sun, 11 Feb 1996 22:13:48 -0800 |
| Reply-To: | Karsten Self <karsten@NEWAGE1.STANFORD.EDU> |
| Sender: | "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU> |
| From: | Karsten Self <karsten@NEWAGE1.STANFORD.EDU> |
| Subject: | Re: Loops and Subroutines |
|
| In-Reply-To: | <4fg704$gtu@msunews.cl.msu.edu> |
|---|
Jim,
A couple of points.
1. In SAS, DATA steps and Procedures are totally different beasts.
Your data step ends with a 'run;' statement, or (implicitly) with the
beginning of another data step or proc statement. If you have an open
'do' loop, this will merely generate one of a number of errors. Most
likely your other errors relate to the data set you thought you were
creating not existing.
2. (As noted by another SAS-L'er) you *can* bundle groups of data steps
and procedures by using the SAS macro facility. This isn't as imposing
as it sounds, but it is a fairly complex addition to BASE SAS, and
has a number of quirks. Chief thing to realize is that the Macro facility
controls how code is GENERATED, not how it is EXECUTED. Read the
documentation on the macro facility for more information.
You might solve your problem with a macro looking something like:
%macro loopit(loops= );
%do i = 1 %to &loops;
data /* whatever */;
run;
proc /* whatever */;
run;
%end;
%mend loopit;
* to execute the macro;
%loopit(loops= 12);
Post me your code, I'll be happy to offer you more suggestions.
On Fri, 9 Feb 1996, Jim Stansell wrote:
> Hi --
>
> I'm using SAS for Windows (6.10) and am having trouble with executing
> a block of code a specific number of times.
>
> I know that I can set up a DO loop in a DATA statement like this:
>
> data temp;
> do x=1 to 10;
> [VARIOUS SAS STATEMENTS]
> end;
>
>
> But, the block of code that I want to run contains a couple of PROCS,
> as well as additional DATA statements. If I insert the code where the
> [VARIOUS SAS STATEMENTS] line appears above, I get tons of error
> messages. Also, whenever I try to branch out of the loop (with a GOTO
> or LINK statement), run the code, and then return, I have the same
> types of problems.
>
> I realize that this is probably too sketchy to be of much help, but I
> was trying to keep this as short as possible.
>
> If you have any suggestions, I'd love to hear them. Also, if you would
> like more detail, please e-mail me, and I'll be glad to send you a
> lengthier message!
>
> Thanks in advance.
>
>
>
> Jim Stansell
> Institute for Public Policy and Social Research
> 321 Berkey Hall
> Michigan State University
> East Lansing, MI 48824-1111
>
---------------------------------------------
Karsten M. Self -- Sr. SAS Programmer/Analyst
Sierra Information Services, Inc.
Contracting for NBER at Stanford University
Karsten@newage1.Stanford.EDU
KMSelf@ix.netcom.com
What part of gestalt don't you understand?
|