Hi All,
Please find below the the input dataset containing 1 observation with 16 var.
which i want to convert as the output dataset having 4 obs with 4 var (4x4 format).
could you please let me know the logic that i can use to do it programatically.
| Input dataset | |||||||||||||||
| res1 | res2 | res3 | res4 | res5 | res6 | res7 | res8 | res9 | res10 | res11 | res12 | res13 | res14 | res15 | res16 |
| 1 | 0.866025 | 0.57735 | 0.75 | 0.866025 | 1 | 0.333333 | 0.57735 | 0.57735 | 0.333333 | 1 | 0.866025 | 0.75 | 0.57735 | 0.866025 | 1 |
output dataset to be generated:-
| prod1 | prod2 | prod3 | prod4 |
| 1 | 0.866025 | 0.57735 | 0.75 |
| 0.866025404 | 1 | 0.333333 | 0.57735 |
| 0.577350269 | 0.333333 | 1 | 0.866025 |
| 0.75 | 0.57735 | 0.866025 | 1 |
regards,
karthik.
This should work:
data have;
input res1 res2 res3 res4 res5 res6 res7 res8 res9 res10 res11 res12 res13 res14 res15 res16;
datalines;
1 0.866025 0.57735 0.75 0.866025 1 0.333333 0.57735 0.57735 0.333333 1 0.866025 0.75 0.57735 0.866025 1
;
run;
data want (keep=prod:);
set have;
array res{16};
array prod{4} 8;
do i=0 to 3;
do j=1 to 4;
prod{j}=res{(i*4)+j};
end;
output;
end;
run;
cou;d not see the complete code,can you resend.
Its all there, in the grey box middle of the post?
A slight modification of RW9's code would use a single DO loop rather than two nested DO loops:
do i=1 to 16;
prod{mod(i-1,4)+1}=res{i};
if ~mod(i,4) then output;
end;
It looks like a correlation matrix to me. You can alternatively put RES1-RES16 into a two dimensional array. I added some of the compenents of a TYPE=CORR data set _TYPE_ _NAME_.
data have;
input res1-res16;
datalines;
1 0.866025 0.57735 0.75
0.866025 1 0.333333 0.57735
0.57735 0.333333 1 0.866025
0.75 4.57735 0.866025 1
;;;;
run;
data _2d(type=corr);
retain _type_ 'CORR';
length _name_ $32;
set have;
array res[4,4] res:;
array prod[4];
keep prod: _type_ _name_;;
do i=1 to hbound(res,1);
_name_ = vname(prod[i]);
do j=1 to hbound(res,2);
prod[j]=res[i,j];
end;
output;
end;
run;
It is IML thing.
1)
data have;
input res1-res16;
datalines;
1 0.866025 0.57735 0.75
0.866025 1 0.333333 0.57735
0.57735 0.333333 1 0.866025
0.75 4.57735 0.866025 1
;;;;
run;
proc iml;
use have;
read all var _num_ into x;
close;
y=shape(x,4);
create want from y;
append from y;
close;
quit;
2)
data want;
set have;
array x{*} _numeric_;
do i=1 to dim(x) by 4;
pred1=x{i};pred2=x{i+1};pred3=x{i+2};pred4=x{i+3};
output;
end;
keep pred:;
run;
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!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.