<?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: Turning a list of data into a 2D table? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Turning-a-list-of-data-into-a-2D-table/m-p/7384#M84</link>
    <description>Thanks to both of you.  That Proc Transpose is particularly efficient.  What was taking me ~20 seconds to run now takes less than 2 seconds.</description>
    <pubDate>Tue, 11 Mar 2008 17:21:14 GMT</pubDate>
    <dc:creator>MBI</dc:creator>
    <dc:date>2008-03-11T17:21:14Z</dc:date>
    <item>
      <title>Turning a list of data into a 2D table?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Turning-a-list-of-data-into-a-2D-table/m-p/7381#M81</link>
      <description>Hi All,&lt;BR /&gt;
&lt;BR /&gt;
I've got a table that looks like this:&lt;BR /&gt;
Name	Exam	Grade&lt;BR /&gt;
Andy	Q1	A&lt;BR /&gt;
Andy	Q2	B&lt;BR /&gt;
Andy	Q3	C&lt;BR /&gt;
Bob	Q1	.&lt;BR /&gt;
Bob	Q2	B&lt;BR /&gt;
Bob	Q3	B&lt;BR /&gt;
Bob	Q4	C&lt;BR /&gt;
Chris	Q1	D&lt;BR /&gt;
Chris	Q3	A&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
And I want to turn it into this:&lt;BR /&gt;
Name	Q1	Q2	Q3	Q4&lt;BR /&gt;
Andy	A	B	C	.&lt;BR /&gt;
Bob	.	B	B	C&lt;BR /&gt;
Chris	D	.	A	.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
I am currently doing this with an Array, a pair of nested do loops, and a Proc Report (DEFINE Name / GROUP;) but this takes a bit of time.  Is there a more efficient way of doing this?&lt;BR /&gt;
&lt;BR /&gt;
Thanks,&lt;BR /&gt;
&lt;BR /&gt;
MBI</description>
      <pubDate>Mon, 10 Mar 2008 15:19:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Turning-a-list-of-data-into-a-2D-table/m-p/7381#M81</guid>
      <dc:creator>MBI</dc:creator>
      <dc:date>2008-03-10T15:19:18Z</dc:date>
    </item>
    <item>
      <title>Re: Turning a list of data into a 2D table?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Turning-a-list-of-data-into-a-2D-table/m-p/7382#M82</link>
      <description>Hi:&lt;BR /&gt;
  One thing you could do is write your report directly from the DATA step program. I did NOT use ARRAYS in this program, just for ease of the example. But if you know how to use ARRAYS, then you can figure out how to change the program accordingly.&lt;BR /&gt;
 &lt;BR /&gt;
 cynthia&lt;BR /&gt;
[pre]&lt;BR /&gt;
** first, make some data;&lt;BR /&gt;
data student;&lt;BR /&gt;
  infile datalines;&lt;BR /&gt;
  input name $ exam $ grade $;&lt;BR /&gt;
return;&lt;BR /&gt;
datalines;&lt;BR /&gt;
Andy Q1 A&lt;BR /&gt;
Andy Q2 B&lt;BR /&gt;
Andy Q3 C&lt;BR /&gt;
Bob Q1 B&lt;BR /&gt;
Bob Q2 B&lt;BR /&gt;
Bob Q3 C&lt;BR /&gt;
Chris Q1 D&lt;BR /&gt;
Chris Q3 A&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
      &lt;BR /&gt;
** now, write the report using DATA _NULL_;&lt;BR /&gt;
title 'Using DATA _NULL_';&lt;BR /&gt;
 &lt;BR /&gt;
ods listing;&lt;BR /&gt;
ods html file='c:\temp\writerept.html' style=sasweb;&lt;BR /&gt;
   &lt;BR /&gt;
data _null_;&lt;BR /&gt;
  set student;&lt;BR /&gt;
  by name;&lt;BR /&gt;
  retain x1 x2 x3;&lt;BR /&gt;
  file print ods=(variables=(name x1 x2 x3));&lt;BR /&gt;
  if first.name then do;&lt;BR /&gt;
     x1 = '.';&lt;BR /&gt;
     x2 = '.';&lt;BR /&gt;
     x3 = '.';&lt;BR /&gt;
  end;&lt;BR /&gt;
  if exam = 'Q1' then x1 = grade;&lt;BR /&gt;
     else if exam = 'Q2' then  x2 = grade;&lt;BR /&gt;
     else if exam = 'Q3' then  x3 = grade;&lt;BR /&gt;
  if last.name then do;&lt;BR /&gt;
    put name x1 x2 x3;&lt;BR /&gt;
  end;&lt;BR /&gt;
  label x1 = 'Q1'&lt;BR /&gt;
        x2 = 'Q2'&lt;BR /&gt;
        x3 = 'Q3'&lt;BR /&gt;
        name = 'Student Name';&lt;BR /&gt;
run;&lt;BR /&gt;
ods html close;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Mon, 10 Mar 2008 22:07:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Turning-a-list-of-data-into-a-2D-table/m-p/7382#M82</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2008-03-10T22:07:29Z</dc:date>
    </item>
    <item>
      <title>Re: Turning a list of data into a 2D table?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Turning-a-list-of-data-into-a-2D-table/m-p/7383#M83</link>
      <description>You could try:&lt;BR /&gt;
&lt;BR /&gt;
proc transpose data=student out=studtrans (drop=_name_);&lt;BR /&gt;
	by name;&lt;BR /&gt;
	var grade;&lt;BR /&gt;
	id exam;&lt;BR /&gt;
run;</description>
      <pubDate>Tue, 11 Mar 2008 07:43:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Turning-a-list-of-data-into-a-2D-table/m-p/7383#M83</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-03-11T07:43:52Z</dc:date>
    </item>
    <item>
      <title>Re: Turning a list of data into a 2D table?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Turning-a-list-of-data-into-a-2D-table/m-p/7384#M84</link>
      <description>Thanks to both of you.  That Proc Transpose is particularly efficient.  What was taking me ~20 seconds to run now takes less than 2 seconds.</description>
      <pubDate>Tue, 11 Mar 2008 17:21:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Turning-a-list-of-data-into-a-2D-table/m-p/7384#M84</guid>
      <dc:creator>MBI</dc:creator>
      <dc:date>2008-03-11T17:21:14Z</dc:date>
    </item>
  </channel>
</rss>

