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

yes, it worked, thanks a lot 🙂 🙂

Ksharp
Super User

OK. You mean this.

 

data have;
infile cards dlm='09'x truncover;
input P_ID $	Col	Year $	c1	c2	c3	c4	c5	c6	c7	c8	c9;
cards;
A	1	Y1	0.932606	0	0	0	0.059015	0.002698	0.003264	0.00071	0.001707
A	2	Y1	0	0.868185	0	0	0.1086	0.008444	0.008169	0.001671	0.004932
A	3	Y1	0	0	0.823402	0	0.14322	0.012453	0.010085	0.002494	0.008346
A	4	Y1	0	0	0	0.758853	0.178104	0.024061	0.016185	0.00652	0.016278
A	5	Y1	0	0	0	0	0.798871	0.031061	0.081029	0.021842	0.067197
A	6	Y1	0	0	0	0	0.298265	0.213144	0.150618	0.049483	0.288489
A	7	Y1	0	0	0	0	0.179519	0.021707	0.239906	0.084662	0.474207
A	8	Y1	0	0	0	0	0.039876	0.005683	0.022931	0.053959	0.877551
A	9	Y1	0	0	0	0	0.010017	0.001072	0.00444	0.003509	0.980962
A	1	Y2	0.932606	0	0	0	0.059015	0.002698	0.003264	0.00071	0.001707
A	2	Y2	0	0.868185	0	0	0.1086	0.008444	0.008169	0.001671	0.004932
A	3	Y2	0	0	0.823402	0	0.14322	0.012453	0.010085	0.002494	0.008346
A	4	Y2	0	0	0	0.758853	0.178104	0.024061	0.016185	0.00652	0.016278
A	5	Y2	0	0	0	0	0.798871	0.031061	0.081029	0.021842	0.067197
A	6	Y2	0	0	0	0	0.298265	0.213144	0.150618	0.049483	0.288489
A	7	Y2	0	0	0	0	0.179519	0.021707	0.239906	0.084662	0.474207
A	8	Y2	0	0	0	0	0.039876	0.005683	0.022931	0.053959	0.877551
A	9	Y2	0	0	0	0	0.010017	0.001072	0.00444	0.003509	0.980962
A	1	Y3	0.932606	0	0	0	0.059015	0.002698	0.003264	0.00071	0.001707
A	2	Y3	0	0.868185	0	0	0.1086	0.008444	0.008169	0.001671	0.004932
A	3	Y3	0	0	0.823402	0	0.14322	0.012453	0.010085	0.002494	0.008346
A	4	Y3	0	0	0	0.758853	0.178104	0.024061	0.016185	0.00652	0.016278
A	5	Y3	0	0	0	0	0.798871	0.031061	0.081029	0.021842	0.067197
A	6	Y3	0	0	0	0	0.298265	0.213144	0.150618	0.049483	0.288489
A	7	Y3	0	0	0	0	0.179519	0.021707	0.239906	0.084662	0.474207
A	8	Y3	0	0	0	0	0.039876	0.005683	0.022931	0.053959	0.877551
A	9	Y3	0	0	0	0	0.010017	0.001072	0.00444	0.003509	0.980962
B	1	Y1	0.932606	0	0	0	0.059015	0.002698	0.003264	0.00071	0.001707
B	2	Y1	0	0.868185	0	0	0.1086	0.008444	0.008169	0.001671	0.004932
B	3	Y1	0	0	0.823402	0	0.14322	0.012453	0.010085	0.002494	0.008346
B	4	Y1	0	0	0	0.758853	0.178104	0.024061	0.016185	0.00652	0.016278
B	5	Y1	0	0	0	0	0.798871	0.031061	0.081029	0.021842	0.067197
B	1	Y2	0.932606	0	0	0	0.059015	0.002698	0.003264	0.00071	0.001707
B	2	Y2	0	0.868185	0	0	0.1086	0.008444	0.008169	0.001671	0.004932
B	3	Y2	0	0	0.823402	0	0.14322	0.012453	0.010085	0.002494	0.008346
B	4	Y2	0	0	0	0.758853	0.178104	0.024061	0.016185	0.00652	0.016278
B	5	Y2	0	0	0	0	0.798871	0.031061	0.081029	0.021842	0.067197
B	1	Y3	0.932606	0	0	0	0.059015	0.002698	0.003264	0.00071	0.001707
B	2	Y3	0	0.868185	0	0	0.1086	0.008444	0.008169	0.001671	0.004932
B	3	Y3	0	0	0.823402	0	0.14322	0.012453	0.010085	0.002494	0.008346
B	4	Y3	0	0	0	0.758853	0.178104	0.024061	0.016185	0.00652	0.016278
B	5	Y3	0	0	0	0	0.798871	0.031061	0.081029	0.021842	0.067197
;
run;

proc iml;
vnames=contents(have);
var_c=vnames[loc(prxmatch('/^c\d+\s*$/i',vnames))];

use have;
read all var{p_id};

id=t(p_id[uniqueby(p_id)]);

do i=1 to ncol(id);
 read all var {year} where (p_id=(id[i]));
 read all var var_c where (p_id=(id[i])) into c;

 y=t(year[uniqueby(year)]);

 do j=1 to ncol(y)-1;
  idx_y1=loc(year=(y[j]));
  idx_y2=loc(year=(y[j+1]));

  y1=c[idx_y1,1:ncol(idx_y1)];
  y2=c[idx_y2,1:ncol(idx_y2)];
  
  yxy=y1*y2;
  want=yxy[,1:(ncol(yxy)-1)]*y2[1:(ncol(yxy)-1),ncol(yxy)];
  
  label="Result for: "+id[i]+" ("+y[j]+"-"+y[j+1]+")";
  label=repeat(label,nrow(want));
  
  labels=labels//label;
  wants=wants//want;

 end;
end;
close;

create want from wants[r=labels];
append from wants[r=labels];
close;
quit;
Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 16 replies
  • 4476 views
  • 1 like
  • 4 in conversation