sas iml - Using a sas lookup table when the column number changes -


i have 2 sas datasets,

table 1                        table 2 col1 col2 col3 col4 col5        b .    1    2    3    4          1  1           1    5    8    6    1          1  4 2    5    9    7    1          4  3 3    6    9    7    1          2  1 4    6    9    7    2          2  2 

where table 1 lookup table values , b in table 2, such can make column c. in table 1 equivalent col1 , b row1 (i.e. new column c in table 2 should read 5,1,7,5,9. how can achieve in sas. thinking of reading table 1 2d array column c = array(a,b), can't work

here's iml solution, first, think 'best' solution - you're using matrix, use matrix language. i'm not sure if there's non-loop method - there may be; if want find out, add tag question , see if rick wicklin happens question.

data table1;   input col1 col2 col3 col4 col5      ; datalines; .    1    2    3    4            1    5    8    6    1          2    5    9    7    1          3    6    9    7    1          4    6    9    7    2     ;;;; run;  data table2; input  b; datalines;  1  1          1  4  4  3  2  1  2  2 ;;;; run;  proc iml; use table1; read var _all_ table1[colname=varnames1]; use table2; read var _all_ table2[colname=varnames2];  print table1; print table2;  table3 = j(nrow(table2),3); table3[,1:2] = table2;  _i = 1 nrow(table3);   table3[_i,3] =  table1[table3[_i,1]+1,table3[_i,2]+1]; end; print table3; quit; 

Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -