Hi all,
I would appreciate your help on the following.
I have two data sets (arrays)
Data X
| V1 | V2 | V3 | V4 | V5 |
| 2 | 1 | 4 | 6 | 3 |
| 4 | 5 | 2 | 1 | |
| 7 | 8 | 2 | ||
| 3 | 9 | |||
| 5 |
and Data Y
| A1 | A2 | A3 | A4 | A5 |
| 2 | 1 | 3 | 5 | 6 |
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
| V1 | V2 | V3 | V4 | V5 | V_New |
| 2 | 1 | 4 | 6 | 3 | 18 |
| 4 | 5 | 2 | 1 | 5 | 30 |
| 7 | 8 | 2 | 6 | 30 | 180 |
| 3 | 9 | 9 | 27 | 135 | 810 |
| 5 | 10 | 10 | 30 | 150 | 900 |
Thank you in advance.
Nik


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
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.
Ready to level-up your skills? Choose your own adventure.