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 2010, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 8 Dec 2010 12:14:27 -0500
Reply-To:     Zach Peery <mpeery@WISC.EDU>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Zach Peery <mpeery@WISC.EDU>
Subject:      Simple Population Projections with PROC IML

Hi All,

I would like to multiply a 3x3 matrix with randomly generated values in the 9 elements by a 3*1 vector where each element represents the number of individuals in a particular age class (below denoted "PopulationVector_Initial"). Easy enough, but I would like to do this over and over, where the next step would be to multiply the orginal matrix by the product of the first multiplication - I've denoted this 3*1 vector "PopulationVectorT_1". I would then like to multiply the original matrix and "PopulationVectorT_1" to get "PopulationVectorT_2", and so on. The trouble is, I can't seem figure out how to make the do-loops work. Ideally I would also output the results to a SAS dataset that looked something like this...

Time Age NumberOfIndividuals 1 1 133 (or thereabouts) 1 2 . 1 3 . 2 1 . 2 2 . 2 3 . . . . 100 3 .

Many thanks - Zach

***My clumsy attempt at the code follows;

proc iml;

a = ranuni(-1); b = ranuni(-1); c = ranuni(-1); d = ranuni(-1); e = ranuni(-1); f = ranuni(-1); g = ranuni(-1); h = ranuni(-1); i = ranuni(-1);

Matrix = (a||b||c) // (d||e||f) // (g||h||i);

InitialNumberAge1 = 100; InitialNumberAge2 = 100; InitialNumberAge3 = 100;

PopulationVector_Initial = (InitialNumberAge1) // (InitialNumberAge2) // (InitialNumberAge3);

PopulationVectorT_1 = Matrix * PopulationVector_Initial; PopulationVectorT_2 = Matrix * PopulationVectorT_1; PopulationVectorT_3 = Matrix * PopulationVectorT_2;

quit; run;


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