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 2025: Save the Date

     SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

    Save the date!

    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.

    SAS Training: Just a Click Away

     Ready to level-up your skills? Choose your own adventure.

    Browse our catalog!

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