<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: SAS Array procedure in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-Array-procedure/m-p/236963#M43429</link>
    <description>&lt;P&gt;Below is a way to do it using a macro and the Transpose Procedure and then merging the transposed data sets together.&amp;nbsp; It should get you what you are looking for in the output data.&amp;nbsp; If arrays are required, that can be adjusted too.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID$ Time X Y Z;
datalines;
1 10 1 2 3
1 11 4 5 6
1 12 7 8 9
2 13 10 20 30
2 14 . . .
2 15 40 . 50
3 16 15 . .
3 17 25 36 37
3 18 35 36 37
;
run;

proc sort data=have;
by ID;
run;

%macro transpose(var,n);
%if &amp;amp;n^=3 %then %do;
proc transpose data=have prefix=&amp;amp;var out=want_&amp;amp;var (drop=_NAME_);
by ID;
var &amp;amp;var;
run;
%end;
%else %do;
proc transpose data=have prefix=&amp;amp;var out=want_&amp;amp;var (drop=_NAME_);
by ID;
var &amp;amp;var;
run;

data want;
merge want_X want_Y want_&amp;amp;var;
run;
%end;
%mend;
%transpose(X,1)
%transpose(Y,2)
%transpose(Z,3);&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 30 Nov 2015 14:33:00 GMT</pubDate>
    <dc:creator>dcruik</dc:creator>
    <dc:date>2015-11-30T14:33:00Z</dc:date>
    <item>
      <title>SAS Array procedure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Array-procedure/m-p/236932#M43425</link>
      <description>&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/964i43BE26D1B7E61C91/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" alt="SAS array.png" title="SAS array.png" /&gt;&lt;/P&gt;&lt;BR /&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/12101iC59761AACD0D303E/image-size/large?v=1.0&amp;amp;px=600" border="0" alt="SAS array.png" title="SAS array.png" /&gt;</description>
      <pubDate>Mon, 30 Nov 2015 12:45:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Array-procedure/m-p/236932#M43425</guid>
      <dc:creator>Ngkl2001</dc:creator>
      <dc:date>2015-11-30T12:45:37Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Array procedure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Array-procedure/m-p/236963#M43429</link>
      <description>&lt;P&gt;Below is a way to do it using a macro and the Transpose Procedure and then merging the transposed data sets together.&amp;nbsp; It should get you what you are looking for in the output data.&amp;nbsp; If arrays are required, that can be adjusted too.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID$ Time X Y Z;
datalines;
1 10 1 2 3
1 11 4 5 6
1 12 7 8 9
2 13 10 20 30
2 14 . . .
2 15 40 . 50
3 16 15 . .
3 17 25 36 37
3 18 35 36 37
;
run;

proc sort data=have;
by ID;
run;

%macro transpose(var,n);
%if &amp;amp;n^=3 %then %do;
proc transpose data=have prefix=&amp;amp;var out=want_&amp;amp;var (drop=_NAME_);
by ID;
var &amp;amp;var;
run;
%end;
%else %do;
proc transpose data=have prefix=&amp;amp;var out=want_&amp;amp;var (drop=_NAME_);
by ID;
var &amp;amp;var;
run;

data want;
merge want_X want_Y want_&amp;amp;var;
run;
%end;
%mend;
%transpose(X,1)
%transpose(Y,2)
%transpose(Z,3);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 30 Nov 2015 14:33:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Array-procedure/m-p/236963#M43429</guid>
      <dc:creator>dcruik</dc:creator>
      <dc:date>2015-11-30T14:33:00Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Array procedure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Array-procedure/m-p/236973#M43430</link>
      <description>thank you for your help and good answer. however, marco, proc transpose are not allowed. i can only use array data step to do it. sorry .</description>
      <pubDate>Mon, 30 Nov 2015 14:54:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Array-procedure/m-p/236973#M43430</guid>
      <dc:creator>Ngkl2001</dc:creator>
      <dc:date>2015-11-30T14:54:14Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Array procedure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Array-procedure/m-p/236975#M43431</link>
      <description>here is my raw data file, in my google drive&lt;BR /&gt;&lt;A href="https://drive.google.com/open?id=0BzqllIWlzJosWGZSdmkzZ0RIeDA" target="_blank"&gt;https://drive.google.com/open?id=0BzqllIWlzJosWGZSdmkzZ0RIeDA&lt;/A&gt;</description>
      <pubDate>Mon, 30 Nov 2015 14:58:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Array-procedure/m-p/236975#M43431</guid>
      <dc:creator>Ngkl2001</dc:creator>
      <dc:date>2015-11-30T14:58:14Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Array procedure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Array-procedure/m-p/236977#M43432</link>
      <description>&lt;P&gt;I think you can find the solution in&amp;nbsp;&lt;A href="http://www.lexjansen.com/phuse/2009/tu/tu01.pdf" target="_blank"&gt;this article&lt;/A&gt;&amp;nbsp;(see Example 1 there).&lt;/P&gt;</description>
      <pubDate>Mon, 30 Nov 2015 15:03:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Array-procedure/m-p/236977#M43432</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2015-11-30T15:03:36Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Array procedure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Array-procedure/m-p/236979#M43433</link>
      <description>thank you very much. let me study it first. really appreciate your help</description>
      <pubDate>Mon, 30 Nov 2015 15:10:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Array-procedure/m-p/236979#M43433</guid>
      <dc:creator>Ngkl2001</dc:creator>
      <dc:date>2015-11-30T15:10:31Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Array procedure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Array-procedure/m-p/236989#M43434</link>
      <description>Here's a good walk through for future reference. &lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://www.ats.ucla.edu/stat/sas/modules/widetolong_data.htm" target="_blank"&gt;http://www.ats.ucla.edu/stat/sas/modules/widetolong_data.htm&lt;/A&gt;</description>
      <pubDate>Mon, 30 Nov 2015 15:31:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Array-procedure/m-p/236989#M43434</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-11-30T15:31:02Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Array procedure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Array-procedure/m-p/237003#M43436</link>
      <description>libname rawfile 'c:\';&lt;BR /&gt;run;&lt;BR /&gt;proc sort data=rawfile.man;&lt;BR /&gt;by id;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data ROWOBS;&lt;BR /&gt;set rawfile.man;&lt;BR /&gt;by id;&lt;BR /&gt;array x_var(3) X1-X3 ;&lt;BR /&gt;array y_var(3) Y1-Y3 ;&lt;BR /&gt;array z_var(3) Z1-Z3;&lt;BR /&gt;if first.id then do i = 1 to 3;&lt;BR /&gt;x_var(i) = .;&lt;BR /&gt;y_var(i) = .;&lt;BR /&gt;z_var(i) = .;&lt;BR /&gt;end;&lt;BR /&gt;j = time;&lt;BR /&gt;x_var(j) = x;&lt;BR /&gt;y_var(j) = y;&lt;BR /&gt;z_var(j) = z;&lt;BR /&gt;if last.id then output;&lt;BR /&gt;retain x1-x3 y1-y3 z1-z3;&lt;BR /&gt;drop i j time x y z;&lt;BR /&gt;run;</description>
      <pubDate>Mon, 30 Nov 2015 15:54:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Array-procedure/m-p/237003#M43436</guid>
      <dc:creator>Ngkl2001</dc:creator>
      <dc:date>2015-11-30T15:54:43Z</dc:date>
    </item>
  </channel>
</rss>

