1 data A;2 input Name $ A B;3 cards;4X2 45X3 26X4 47Y5 18Y6 29Y7 1Ten ; One run; A%macro transpose; - proc SQL Noprint; - SelectCOUNT (distinct name) Into:name_n fromA; the SelectDistinct name Into:name_ separated by"|" fromA; - quit; -% Doi =1%to &Name_n; -%let _name =%scan ("&name_", &i,"|"); + proc SQL Noprint; - SelectCount (a) Into:na fromAwhereName="&_name" ; + SelectName into:name_x fromAwhereName="&_name"; A SelectA INTO:AA separated by"|" fromAwhereName="&_name"; at SelectCount (b) into:nb fromAwhereName="&_name"; - SelectName into:name_x fromAwhereName="&_name"; - Selectb INTO:BB separated by"|" fromAwhereName="&_name"; - quit; - data tmp; - SetA (drop=name); in run; - proc SQL Noprint; to SelectName Into:varlist separated by"|" fromDictionary.columns + whereLibname=" Work"and memname="TMP"; - quit; the data _null_; *Nvar=count ("&varlist","|")+1; $Call Symput ("Nvar", Nvar);Panax Notoginseng run; -% Doj=1%to &Nvar; the%let _var=%scan (%bquote (&varlist), &j,"|"); +Data b&i.&j. (keep=name _name_ col:); AName="&_name"; the_name_="&_var"; +Array _a[&na]; -Array _b[&NB]; $ Doi =1To &na; $_a[i]=scan ("&aa"I"|"); - end; - Doj =1To &nb; the_b[j]=scan ("&BB"J"|"); - end;Wuyi% Dop=1%to &&n&_var; theRename _&_var.&p=col&p; -%end; Wu proc Sort nodupkey;by name col:; - run; About%end; $%end; - data wanted; - SetB:; - run; A%mend transpose; +%transpose
Just for fun.
yant07
Transpose's Data step implementation