```Date: Tue, 20 Oct 2009 10:03:59 -0700 Reply-To: Tom Abernathy Sender: "SAS(r) Discussion" From: Tom Abernathy Organization: http://groups.google.com Subject: Re: Matlab matrix-calculation to SAS Comments: To: sas-l@uga.edu Content-Type: text/plain; charset=windows-1252 Annette - Can you explain what you want to do as operations on variables and observations of a SAS dataset rather than as matrix operations. It looks like you have a dataset with values ID, DELDAY (Perhaps delivery day?) and CALCULATIONDAY (is this the same for all IDs?). You are defining TAU (age) as the number of days since the delivery day by taking the difference. And you want to create a new value DENOM that is the sum over a range of times of the values of the LAMBDA and F1 functions? I am sure this is totally wrong for what you want to do but it sounds like you want something like: data new; set old; tau = calculationday - delday; denom=0; do t1= 1 to min(tau-1,365); t2=tau-t1; denum=sum(denum,lambda(t1),f1(t2)); end; run; If that is basically correct then your next issue is what are LAMBDA and F1? Are they something than can be written as a expression in SAS code? Are they standard statistical functions that SAS already has? If so then just replace 'lamda(t1)' with equivalent SAS code. If not and the only way to store them is as "vectors" or SAS datasets then you have a couple of easy options to "merge" them in with you observed data. So instead of using LAMBDA(t1) you have a datasets with 365 observations and the variable LAMBDA. same for F1. Someone could explain how to use hashes or formats, but I like to use the set statement with the point= option. It is easier for me to understand. In that case replace denum=sum(denum,lambda(t1),f1(t2)); with set lambda point=t1; set f1 point=t2; denum=sum(denum,lambda,f1); - Tom Abernathy On Oct 20, 10:05 am, annette.hulta...@SCANIA.COM (Annette Hultaker) wrote: > Hi, > > I have problems converting a piece of Matlab-code into SAS. It concerns an > iteration for a number (Nx) of items, all of different age. Depending on > the age of each item I have to use parts of two function lambda(t1) and Fl > (t2). > > I have calculated lambda and Fl earlier in the program. I can store them > either as data-step variables or as macro variables using call symput > ('lambda'||strip(t1),lambda);. The dataset with e.g lambda contains one > column t1 and one column with the lambda-value. > > IT.delday is stored in a data-set containing item-information. > > For those of you how are not familiar with Matlab. The function min takes > the minimum value of tau-1 and 365 and t1 is a vector with values spanning > from 1 to the minimum value just calculated, in steps of 1. t2 is thus also > a vector. .* denotes element-wise multiplication. > > for j = 1:Nx(k), %There are Nx items for period k > tau = calculationday-IT.delday(j); %tau is age of item on calculation day > t1 = [1:1:min(tau-1,365)]; > t2 = tau-t1; > denom(k) = denom(k) + sum(lambda(t1).*Fl(t2)); > end; > > I really appreciate your help. > Annette ```

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