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 (March 1997, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 14 Mar 1997 11:14:27 -0500
Reply-To:     Robert Hamer <hamer@RCI.RUTGERS.EDU>
Sender:       "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From:         Robert Hamer <hamer@RCI.RUTGERS.EDU>
Organization: Rutgers University
Subject:      Re: symbolic constant in data ?

Curtis Mack <mackce@dshs.wa.gov> writes:

>Arthur Ellen wrote: >> Is there a way to use symbolic constants in a data step with >> arrays and do: >> data new; >> n=5; /* symbolic constant */ >> array score(n) score1-score5 (1, 2, 3, 4, 5); >> do i = 1 to n; ... inside of loop deleted to save bandwidth and space ... >> end; >> >> I'd like to set n for the array or arrays to a number as >> well as use it in the loop without having to specify it in each >> place.

>Congratulations, You have just moved into the world of SAS macros. You >may want to read up on the subject, but your sample would look like >this:

... macro deleted ...

Although a macro is a fine way to do this, it is not necessary, and if the original question poster is not familiar with macros, it might be better not to use them.

She can acomplish what she wants as follows:

array score {*} score1-score5 (1,2,3,4,5); do i=1 to dim(score); ... stuff inside the loop ... end;

The {*} tells the SAS data step compiler to simply count the number of elements in the array and make the array that long. The dim(score) is a built-in function that returns the number of elements in the array, and use it as the limit on the loop.

-- --(Signature) Robert M. Hamer hamer@rci.rutgers.edu 908 235 4218 Do not send me unsolicited email advertisements. I have never and will never buy. I will complain to your postmaster. "Mit der Dummheit kaempfen Goetter selbst vergebens" -- Schiller


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