Help using Base SAS procedures

from column to triangle matrix

Accepted Solution Solved
Reply
Contributor
Posts: 57
Accepted Solution

from column to triangle matrix

Good morning

I want to get an triangle matrix from a column like this:

data have;

input i column;

cards;

1 0.5

2 0.6

3 0.7

4 0.8

;

run;

data want;

input i col1 col2 col3 col4;

cards;

1 0.5 0.5 0.5 0.5

2 .     0.6 0.6 0.6

3 .     .    0.7 0.7

4 .    .     . 0.8

;

run;

Any help is appreciated!

BR  Dingdang


Accepted Solutions
Solution
‎05-04-2015 07:20 AM
Trusted Advisor
Posts: 1,204

Re: from column to triangle matrix

data have;

input i column;

cards;

1 0.5

2 0.6

3 0.7

4 0.8

;

run;

data want(drop=column j);

set have;

array col(*) col1-col4;

do j=_n_ to dim(col);

   col(j)=column;

end;

run;

View solution in original post


All Replies
Super Contributor
Posts: 336

Re: from column to triangle matrix

data have;
input i column;
cards;
1 0.5
2 0.6
3 0.7
4 0.8
;
run;

Data _NULL_;
  Have_File=Open("have");
  Obs=Attrn(Have_File,"Nobs");
  Call SymputX ("Obs",Obs);
Run;

Data Want (Keep=i Col1-Col&Obs.);
  Array Col Col1-Col&Obs.;
  Set have;
  Do j=1 To Dim(Col);
    Col{j}=IfN(i le j,column,.);
  End;
Run;

Respected Advisor
Posts: 3,777

Re: from column to triangle matrix

data haveV / view=haveV;
   set have nobs=nobs;
   do c = i to nobs;
      output;
     
end;
  
run;
proc transpose data=havev out=want2(drop=_name_);
   by i;
   var column;
   id c;
   run;
Solution
‎05-04-2015 07:20 AM
Trusted Advisor
Posts: 1,204

Re: from column to triangle matrix

data have;

input i column;

cards;

1 0.5

2 0.6

3 0.7

4 0.8

;

run;

data want(drop=column j);

set have;

array col(*) col1-col4;

do j=_n_ to dim(col);

   col(j)=column;

end;

run;

Contributor
Posts: 57

Re: from column to triangle matrix

hi,

thank you for your code. this is exactly what I tried to do but failed. The other answers were also very good and interesting.

BR  Dingdang

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 286 views
  • 9 likes
  • 4 in conversation