Date: Tue, 23 Oct 2007 14:16:03 -0400
Reply-To: Sigurd Hermansen <HERMANS1@WESTAT.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Sigurd Hermansen <HERMANS1@WESTAT.COM>
Subject: Re: Newbie wants to program
Content-Type: text/plain; charset="us-ascii"
F**TRAN isn't actually an assembler language, just an early procedural
language. With some effort you can write SAS programs that look much
like F**TRAN. Sounds as if you are heading in that direction.
You have selected a 'look ahead in a file' problem and an array
solution. SAS offers array solutions as well, but also offers a couple
less procedural (more declarative) alternatives:
- sort the dataset in descending order and use the LAG3() function to
look back three rows. The first three rows (in descending order) will
then have missing or NULL values and can be deleted;
- assign sequential row numbers to the rows of data and use SAS SQL to
join the dataset to itself (reflexive join) on n=n+3.
Even better, use SAS procedures appropriate for analysis of time series
or repeating measures or groups (or whatever you are analyzing). For
that you will need to add identifying information to your data array.
If you really prefer to stay in the world of numeric arrays and you have
PROC IML licensed, the matrix operations in IML may give you what you
want. Much depends on what you might want to do next.
From: firstname.lastname@example.org [mailto:email@example.com]
On Behalf Of Pat
Sent: Tuesday, October 23, 2007 1:30 PM
Subject: Newbie wants to program
I work with financial data at a university using SAS 9.1. In the past,
I've manipulated my data using an assembly language program that I'm too
embarrassed to name (but it starts with an F and ends with a tran) and
then entered it into SAS to do regressions and other statistical procs.
I've heard that this is a waste of time and that I can just do all of
the manipulations in SAS. I am having trouble figuring out how to do
that. I know that SAS has an array statement, but I don't think that I
really want to make an entire row into an array. Let me try to explain
what I'd like to do. It's pretty simple:
x1 y1 z1
x2 y2 z2
. . .
. . .
xn yn zn
I would like to be able to create a variable, call it w, and make it an
array with dimensions n-3 rows by 1 column. Then, do something like
this, but using SAS code:
if x(i+3) not equal to -99
then w(i) = x(i+3) + y(i+3) / z(i+3)
w(i) = -99
Thanks for your attention