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 (October 2007, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 24 Oct 2007 09:50:33 -0400
Reply-To:     "Howard Schreier <hs AT dc-sug DOT org>" <nospam@HOWLES.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "Howard Schreier <hs AT dc-sug DOT org>" <nospam@HOWLES.COM>
Subject:      Re: Newbie wants to program

On Tue, 23 Oct 2007 17:29:53 -0000, Pat <PLarkin2@GMAIL.COM> wrote:

>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: > >do i=1,n-3 >if x(i+3) not equal to -99 >then w(i) = x(i+3) + y(i+3) / z(i+3) >else >w(i) = -99 >end if >end do > >Thanks for your attention

You will ultimately be more productive, and happier with SAS, if you don't try to code SAS while thinking like a FORTRAN programmer. First lesson: don't use -99 and the like to flag missing data; use the SAS missing-value features.

IML has its role, but the type of manipulation you present here can be done using commonplace Base SAS tools. Here is a very SAS-like SAS solution for the current problem.

Test data:

data have(keep = x y z); array xyz(3) x y z; do i = 1 to 7; do j = 1 to 3; xyz(j) = ceil(9 * ranuni(123) ); end; if ranuni(123) < 0.4 then x = .; output; end; run;

Solution:

data need(keep = w x y z); set have; set have(firstobs=4 rename = (x=x_ y=y_ z=z_) ); w = x_ + y_ / z_; run;


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