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 (June 2008, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Sat, 21 Jun 2008 02:35:45 +0000
Reply-To:     iw1junk@COMCAST.NET
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Ian Whitlock <iw1junk@COMCAST.NET>
Subject:      Re: Sort of a do loop
Comments: cc: Patrick Moore <pamoore@UAS.ALASKA.EDU>

Summary: Suggestions #iw-value=1

Patrick,

My head is spinning from trying to read you specification. Perhaps you have to be clearer in what you want.

Maybe you want

%do start_year = 2001 %to 2007 ; %do yr = &start_year+1 %to 2008 ; %do j = 1 %to 2 ; %let sem = %scan(01 03,&j) ; %let start_term = &start_year&sem ; %let ret_term = &yr&sem ; ... %end ; %end ; %end ;

or maybe

%do start_year = 2001 %to 2007 ; %let yr = %eval(&start_year+1) ; %do j = 1 %to 2 ; %let sem = %scan(01 03,&j) ; %let start_term = &start_year&sem ; %let ret_term = &yr&sem ; ... %end ; %end ;

I cannot parse the specs well enough to know. If one of the above is not reasonably close to what you want then you will have to explain how START_YEAR is to be determined.

Ian Whitlock =============

Date: Fri, 20 Jun 2008 12:29:32 -0400 Reply-To: Patrick Moore <pamoore@UAS.ALASKA.EDU> Sender: "SAS(r) Discussion" From: Patrick Moore <pamoore@UAS.ALASKA.EDU> Subject: Sort of a do loop Content-Type: text/plain; charset=ISO-8859-1

SAS Gurus:

I need sort of a do loop that will generate two term codes to pull data from a database which records semesters at a university as

200703 which means the 03 or Fall term of 2007 200801 which means the 01 or Spring term of 2008

I need to pull data for a series of semesters for a starting cohort of students for each subsequent term.

The initial value of Start_term should be set to 200103 by the operator. After the first run through the data, it should increment to 200201 and to 200203 after the second run, and so on until it gets to 200801.

When Start_term is 200103, a second macro variable, Return_term should increment through the values 200201, 200203, 200301, 200303, etc. to 200801, and then when Start_term increments to 200201, Return_term should increment through 200203, 200301, 200303200801 and so on.

When Start_term = 200801, Return term should also be 200801 and the loop should end.

I currently have: %let start_year = 2003; %do i= &start_year+1 %to 2008 %by 1; %do j=1 %to 3 %by 1; %let start_term=&start_year.0&j.; %let ret_term=&i.0&j.; quit;

But this has two disadvantages: I have to increment the start year manually, and the do loops pull data for the summer sessions (200302, etc) which I have to eliminate in the output.

Any ideas?


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