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 (December 2009, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Mon, 14 Dec 2009 09:04:20 -0500
Reply-To:     Mike Rhoads <RHOADSM1@WESTAT.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Mike Rhoads <RHOADSM1@WESTAT.COM>
Subject:      Re: SAS dynamic arrays
Comments: To: Håkan Lane <hlane@CLS.DK>
In-Reply-To:  <20091214133122.10436wcl9ieigpp6@webmail.nfit.au.dk>
Content-Type: text/plain; charset="iso-8859-1"

If you are going to calculate the number of years needed, it needs to be done with a macro variable in order to use it for dimensioning the array:

%let numyears=%eval(&slutaar-&startaar+1); Array sampled{&numyears} sampled&startaar - sampled&slutaar; sampled{aar}=1; DROP alder;

By the way, I always like to put such macro statements outside of (prior to) DATA and PROC steps. This reduces the confusion between macro statements and other statements that need to execute within the context of a SAS step.

Better yet, use the * to dimension your array, and you don't have to worry about calculating the number of years required at all:

Array sampled{*} sampled&startaar - sampled&slutaar;

Mike Rhoads RhoadsM1@Westat.com

-----Original Message----- From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Håkan Lane Sent: Monday, December 14, 2009 7:31 AM To: SAS-L@LISTSERV.UGA.EDU Subject: SAS dynamic arrays

I would like to implement an array the size of which is not known a priori. Instead of declaring an implicit value for the number of elements, I wish to find this value from a variable. This can be done in other languages including Fortran.

My attempt to code this as shown below fails.

DATA libout.pdata; SET cpr; byear=aar-alder; numyears=&slutaar-&startaar+1; Array sampled{numyears} sampled&startaar - sampled&slutaar; sampled{aar}=1; DROP alder numyears; IF last.pnr THEN output; ELSE DO; END; RUN;

The idea is to replace a structure with one record every year that a person was in our records with their age so an array with a 1 if they were in and 0 if they weren't. The age (alder from above) is represented with a birthyear. This would quite obviously save a lot of redundant data. The issue is that we might run the program with different start and end years. That is why it would be better for them to be external constants.

Thanks in advance.

Regards,

Hkan Lane


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