Transpose's Data step implementation

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.