dataset - SAS transpose using a part of the name -


i'm here asking for problem proc transpose.

i have dataset made way (i'm going show 3 variables have lots of them)

pr  id  var1a   var1b   var1c   var2a   var2b   var2c   var3a   var3b var3c  1   1   x       x       x       x       x       x       x       x     x 1   2   x       x       x       x       x       x       x       x     x 1   3   x       x       x       x       x       x       x       x     x 2   1   x       x       x       x       x       x       x       x     x 2   2   x       x       x       x       x       x       x       x     x 2   3   x       x       x       x       x       x       x       x     x 

i need output dataset this:

preid   id  var(name)     b   c 1       1   var1(name)  x   x   x 1       1   var2(name)  x   x   x 1       1   var3(name)  x   x   x 1       2   var1(name)  x   x   x 1       2   var2(name)  x   x   x 1       2   var3(name)  x   x   x 1       3   var1(name)  x   x   x 1       3   var2(name)  x   x   x 1       3   var3(name)  x   x   x 

etc preid 2 id 1 2 3, preid 3 id 1 2 3.

so need transpose using name (discriminating b c), have no idea start. can me please?

similar @sushil solution above, 1 less step. since have go data step anyways, may transpose data in step well. in solution proc transpose/data step combined. if had few enough variables i'd remove last transpose well, more flexible if have quite few variables.

data input; infile datalines dsd dlm=',' missover; input pr    :$8.        id    :$8.         var1a :$8.         var1b :$8.         var1c :$8.          var2a :$8.         var2b :$8.         var2c :$8.         var3a :$8.         var3b :$8.        var3c :$8.; datalines4; 1,1,x,x,x,x,x,x,x,x,x 1,2,x,x,x,x,x,x,x,x,x 1,3,x,x,x,x,x,x,x,x,x 2,1,x,x,x,x,x,x,x,x,x 2,2,x,x,x,x,x,x,x,x,x 2,3,x,x,x,x,x,x,x,x,x ;;;; run;  data out1; set input; array vars(*) var1a--var3c; i=1 dim(vars); name=vname(vars(i)); varname=substr(name,1,length(name)-1); group=substr(name,length(name)); value=vars(i); output; end;  drop var1a--var3c; run;  proc transpose data=out1 out=out2; pr id varname; id group; var value; run; 

Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -