BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Nikos
Fluorite | Level 6

Hi all,

I would appreciate your help on the following.

I have two data sets (arrays)

Data X

V1V2V3V4V5
21463
4521
782
39
5

and Data Y

A1A2A3A4A5
21356

I would like to fill the missing lower part of the matrix by successively multiplying the previous non-missing value of Data X with the elements of the Data Y

i.e. for the last observation  10= 5*2 (A1),  10= 10 * 1 (A2), 30=10* 3 (A3) , 150 = 30 * 5 (A4) and 900 = 150 * 6(A5)

Consequently column V_New will be created due to final multiplication.

So  Data Z is the desired one

V1V2V3V4V5V_New
2146318
4521530
782630180
39927135810
5101030150900

Thank you in advance.

Nik

1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19
data v;
   infile cards expandtabs missover;
  
input V1-V5;
   cards;
2  1  4  6  3
4  5  2  1 
7  8  2    
3  9       
5          
;;;;
   run;
proc print;
  
run;
Data a;
   infile cards expandtabs;
  
input A1-A5;
   cards;
2  1  3  5  6
;;;;
   run;
proc print;
  
run;
data mult;
   if _n_ eq 1 then set a;
   set v;
   array v
  • v: Vx;
  •    array a
  • a:;
  •    do i = n(of v
  • );
  •       do j = i to dim(a);
             v[j+1] = a*v;
             end;
         
    end;
      
    drop i j;
       run;
    proc print;
      
    run;
    4-2-2015 12-38-27 PM.png

    View solution in original post

    2 REPLIES 2
    data_null__
    Jade | Level 19
    data v;
       infile cards expandtabs missover;
      
    input V1-V5;
       cards;
    2  1  4  6  3
    4  5  2  1 
    7  8  2    
    3  9       
    5          
    ;;;;
       run;
    proc print;
      
    run;
    Data a;
       infile cards expandtabs;
      
    input A1-A5;
       cards;
    2  1  3  5  6
    ;;;;
       run;
    proc print;
      
    run;
    data mult;
       if _n_ eq 1 then set a;
       set v;
       array v
  • v: Vx;
  •    array a
  • a:;
  •    do i = n(of v
  • );
  •       do j = i to dim(a);
             v[j+1] = a*v;
             end;
         
    end;
      
    drop i j;
       run;
    proc print;
      
    run;
    4-2-2015 12-38-27 PM.png
    Ksharp
    Super User

    I like such kind of questions.

    data v;
       infile cards expandtabs missover; 
       input V1-V5;
       cards; 
    2  1  4  6  3
    4  5  2  1  
    7  8  2     
    3  9        
    5           
    ;;;;
       run; 
       Data a;
       infile cards expandtabs; 
       input A1-A5;
       cards; 
    2  1  3  5  6
    ;;;;
       run; 
    data want;
     if _n_ eq 1 then set a;
     set v;
     array x{*} v1-v5 v_new;
     array y{*} a1-a5;
     do i=1 to dim(x)-1;
       temp=x{i}*y{i};
       if missing(x{i+1}) then x{i+1}=temp;
     end;
     drop temp i a:;
    run;
    
    

    Xia Keshan

    sas-innovate-2024.png

    Don't miss out on SAS Innovate - Register now for the FREE Livestream!

    Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

     

    Register now!

    What is Bayesian Analysis?

    Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

    Find more tutorials on the SAS Users YouTube channel.

    Click image to register for webinarClick image to register for webinar

    Classroom Training Available!

    Select SAS Training centers are offering in-person courses. View upcoming courses for:

    View all other training opportunities.

    Discussion stats
    • 2 replies
    • 732 views
    • 5 likes
    • 3 in conversation