<?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 Create table using arrays from data on 2 other tables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-table-using-arrays-from-data-on-2-other-tables/m-p/63006#M13689</link>
    <description>Hi,&lt;BR /&gt;
Table-X contains people’s names and scores.( sorted via Name )&lt;BR /&gt;
Table-Y is a copy of Table-X but with unique names.(sorted via Name)&lt;BR /&gt;
Table-Z is a copy of Table-Y with the individual scores from Table-X appearing next to the relevant Name. Maximum scores stored = 20.&lt;BR /&gt;
-	How would one create Table-Z ?  Would one use arrays for the max 20 occurance of scores ?&lt;BR /&gt;
Thanks in Advance.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Table-X&lt;BR /&gt;
A 1&lt;BR /&gt;
A 3&lt;BR /&gt;
A 7&lt;BR /&gt;
B 2&lt;BR /&gt;
F 2&lt;BR /&gt;
F 9&lt;BR /&gt;
K 1&lt;BR /&gt;
K 8&lt;BR /&gt;
P 2&lt;BR /&gt;
P 8&lt;BR /&gt;
P 9&lt;BR /&gt;
&lt;BR /&gt;
Table-Y&lt;BR /&gt;
A&lt;BR /&gt;
B&lt;BR /&gt;
F&lt;BR /&gt;
K&lt;BR /&gt;
P&lt;BR /&gt;
&lt;BR /&gt;
Table-Z&lt;BR /&gt;
A 1 3 7&lt;BR /&gt;
B 2&lt;BR /&gt;
F 2 9&lt;BR /&gt;
K 1 8&lt;BR /&gt;
P 2 8 9</description>
    <pubDate>Fri, 06 May 2011 12:50:56 GMT</pubDate>
    <dc:creator>exRhodesian</dc:creator>
    <dc:date>2011-05-06T12:50:56Z</dc:date>
    <item>
      <title>Create table using arrays from data on 2 other tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-table-using-arrays-from-data-on-2-other-tables/m-p/63006#M13689</link>
      <description>Hi,&lt;BR /&gt;
Table-X contains people’s names and scores.( sorted via Name )&lt;BR /&gt;
Table-Y is a copy of Table-X but with unique names.(sorted via Name)&lt;BR /&gt;
Table-Z is a copy of Table-Y with the individual scores from Table-X appearing next to the relevant Name. Maximum scores stored = 20.&lt;BR /&gt;
-	How would one create Table-Z ?  Would one use arrays for the max 20 occurance of scores ?&lt;BR /&gt;
Thanks in Advance.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Table-X&lt;BR /&gt;
A 1&lt;BR /&gt;
A 3&lt;BR /&gt;
A 7&lt;BR /&gt;
B 2&lt;BR /&gt;
F 2&lt;BR /&gt;
F 9&lt;BR /&gt;
K 1&lt;BR /&gt;
K 8&lt;BR /&gt;
P 2&lt;BR /&gt;
P 8&lt;BR /&gt;
P 9&lt;BR /&gt;
&lt;BR /&gt;
Table-Y&lt;BR /&gt;
A&lt;BR /&gt;
B&lt;BR /&gt;
F&lt;BR /&gt;
K&lt;BR /&gt;
P&lt;BR /&gt;
&lt;BR /&gt;
Table-Z&lt;BR /&gt;
A 1 3 7&lt;BR /&gt;
B 2&lt;BR /&gt;
F 2 9&lt;BR /&gt;
K 1 8&lt;BR /&gt;
P 2 8 9</description>
      <pubDate>Fri, 06 May 2011 12:50:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-table-using-arrays-from-data-on-2-other-tables/m-p/63006#M13689</guid>
      <dc:creator>exRhodesian</dc:creator>
      <dc:date>2011-05-06T12:50:56Z</dc:date>
    </item>
    <item>
      <title>Re: Create table using arrays from data on 2 other tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-table-using-arrays-from-data-on-2-other-tables/m-p/63007#M13690</link>
      <description>Hello exRhodesian,&lt;BR /&gt;
&lt;BR /&gt;
This is a solution:&lt;BR /&gt;
[pre]&lt;BR /&gt;
data X;&lt;BR /&gt;
input name $ score;&lt;BR /&gt;
datalines;&lt;BR /&gt;
A 1&lt;BR /&gt;
A 3&lt;BR /&gt;
A 7&lt;BR /&gt;
B 2&lt;BR /&gt;
F 2&lt;BR /&gt;
F 9&lt;BR /&gt;
K 1&lt;BR /&gt;
K 8&lt;BR /&gt;
P 2&lt;BR /&gt;
P 8&lt;BR /&gt;
P 9&lt;BR /&gt;
run;&lt;BR /&gt;
proc sort data=X;&lt;BR /&gt;
  by name;&lt;BR /&gt;
run;&lt;BR /&gt;
proc transpose data=X out=Z (drop=_:) prefix=s_;&lt;BR /&gt;
  var score;&lt;BR /&gt;
  by name;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
Sincerely,&lt;BR /&gt;
SPR</description>
      <pubDate>Fri, 06 May 2011 13:45:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-table-using-arrays-from-data-on-2-other-tables/m-p/63007#M13690</guid>
      <dc:creator>SPR</dc:creator>
      <dc:date>2011-05-06T13:45:48Z</dc:date>
    </item>
    <item>
      <title>Re: Create table using arrays from data on 2 other tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-table-using-arrays-from-data-on-2-other-tables/m-p/63008#M13691</link>
      <description>Give this a whirl:&lt;BR /&gt;
&lt;BR /&gt;
data Narrow;&lt;BR /&gt;
input name $ scr;&lt;BR /&gt;
datalines;&lt;BR /&gt;
A 1&lt;BR /&gt;
A 3&lt;BR /&gt;
A 7&lt;BR /&gt;
B 2&lt;BR /&gt;
F 2&lt;BR /&gt;
F 9&lt;BR /&gt;
K 1&lt;BR /&gt;
K 8&lt;BR /&gt;
P 2&lt;BR /&gt;
P 8&lt;BR /&gt;
P 9&lt;BR /&gt;
run;&lt;BR /&gt;
proc sort data=Narrow;&lt;BR /&gt;
   by name;&lt;BR /&gt;
run;&lt;BR /&gt;
data Wide;&lt;BR /&gt;
   set Narrow;&lt;BR /&gt;
   by Name;&lt;BR /&gt;
   array Score{20};&lt;BR /&gt;
   retain score:;&lt;BR /&gt;
   if First.Name then do;&lt;BR /&gt;
      call missing (of Score{*});&lt;BR /&gt;
	  _index=0;&lt;BR /&gt;
   end;&lt;BR /&gt;
   _index+1;&lt;BR /&gt;
   Score{_index}=scr;&lt;BR /&gt;
   if Last.Name then output;&lt;BR /&gt;
   drop _index scr;&lt;BR /&gt;
run;</description>
      <pubDate>Sun, 08 May 2011 01:30:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-table-using-arrays-from-data-on-2-other-tables/m-p/63008#M13691</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2011-05-08T01:30:25Z</dc:date>
    </item>
    <item>
      <title>Re: Create table using arrays from data on 2 other tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-table-using-arrays-from-data-on-2-other-tables/m-p/63009#M13692</link>
      <description>Another way would be to write a text file that you could read later.  I don't think you'll need table Y for this approach:&lt;BR /&gt;
&lt;BR /&gt;
data _null_;&lt;BR /&gt;
set x;&lt;BR /&gt;
by name;&lt;BR /&gt;
file z /*not sure of the syntax to set lreclen*/;&lt;BR /&gt;
if first.name then put name, score @;&lt;BR /&gt;
else put score @;&lt;BR /&gt;
if last.name then put;</description>
      <pubDate>Sun, 08 May 2011 04:04:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-table-using-arrays-from-data-on-2-other-tables/m-p/63009#M13692</guid>
      <dc:creator>DBailey</dc:creator>
      <dc:date>2011-05-08T04:04:44Z</dc:date>
    </item>
    <item>
      <title>Re: Create table using arrays from data on 2 other tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-table-using-arrays-from-data-on-2-other-tables/m-p/63010#M13693</link>
      <description>[pre]&lt;BR /&gt;
data X;&lt;BR /&gt;
input name $ score;&lt;BR /&gt;
datalines;&lt;BR /&gt;
A 1&lt;BR /&gt;
A 3&lt;BR /&gt;
A 7&lt;BR /&gt;
B 2&lt;BR /&gt;
F 2&lt;BR /&gt;
F 9&lt;BR /&gt;
K 1&lt;BR /&gt;
K 8&lt;BR /&gt;
P 2&lt;BR /&gt;
P 8&lt;BR /&gt;
P 9&lt;BR /&gt;
run;&lt;BR /&gt;
data want(drop=score);&lt;BR /&gt;
 set x;&lt;BR /&gt;
 by name;&lt;BR /&gt;
 length scores $ 50;&lt;BR /&gt;
 retain scores;&lt;BR /&gt;
 if first.name then call missing (scores);&lt;BR /&gt;
 scores=catx(' ',scores,score);&lt;BR /&gt;
 if last.name then output;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
      <pubDate>Mon, 09 May 2011 01:04:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-table-using-arrays-from-data-on-2-other-tables/m-p/63010#M13693</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-05-09T01:04:23Z</dc:date>
    </item>
    <item>
      <title>Re: Create table using arrays from data on 2 other tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-table-using-arrays-from-data-on-2-other-tables/m-p/63011#M13694</link>
      <description>Hi, many thanks for your assistance. After trying them out , yours, SPR, seemed to work spot on.&lt;BR /&gt;
These are actually for Towns/Suburbs here in South Africa with Postal codes where,eg. there are 3 towns in SA with the name of Newtown. I figured it much better to create a table as seen below rather than have a huge long table where Newtown would appear 3 times. Some names appear 11 times. Thanks once again,&lt;BR /&gt;
Adrian from Johannesburg.&lt;BR /&gt;
&lt;BR /&gt;
Code used&lt;BR /&gt;
:&lt;BR /&gt;
proc sort data=LOCAL.BOX; &lt;BR /&gt;
by TOWN BOX;&lt;BR /&gt;
run;&lt;BR /&gt;
proc transpose data=LOCAL.BOX out=COMBINE (drop=_:) prefix=s_; &lt;BR /&gt;
var BOX; &lt;BR /&gt;
by TOWN;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
NEW BRIGHTON.......6200	7070&lt;BR /&gt;
NEWCAVE...............	2380	6255	9400	9944	9950&lt;BR /&gt;
NEWCLARE.............	2112		&lt;BR /&gt;
NEWLANDS.............	0049	5201	7725&lt;BR /&gt;
NEWTON.................	4380	8420	&lt;BR /&gt;
NEWTON PARK........6055		&lt;BR /&gt;
NEWTOWN...............2113	4310	4400</description>
      <pubDate>Mon, 09 May 2011 08:36:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-table-using-arrays-from-data-on-2-other-tables/m-p/63011#M13694</guid>
      <dc:creator>exRhodesian</dc:creator>
      <dc:date>2011-05-09T08:36:46Z</dc:date>
    </item>
    <item>
      <title>Re: Create table using arrays from data on 2 other tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-table-using-arrays-from-data-on-2-other-tables/m-p/63012#M13695</link>
      <description>Hi SASJedi   - tried out yours and it also works spot on as seen below. Thanks once again.&lt;BR /&gt;
Adrian in Johannesburg&lt;BR /&gt;
&lt;BR /&gt;
proc sort data=LOCAL.BOX;&lt;BR /&gt;
by TOWN;&lt;BR /&gt;
run;&lt;BR /&gt;
data BOX_COMBINED;&lt;BR /&gt;
set LOCAL.BOX;&lt;BR /&gt;
by TOWN;&lt;BR /&gt;
array BOXES{20};&lt;BR /&gt;
retain BOX:;&lt;BR /&gt;
if First.TOWN then do;&lt;BR /&gt;
call missing (of BOXES{*});&lt;BR /&gt;
_index=0;&lt;BR /&gt;
end;&lt;BR /&gt;
_index+1;&lt;BR /&gt;
BOXES{_index}=BOX;&lt;BR /&gt;
if Last.TOWN then output;&lt;BR /&gt;
drop _index BOX;&lt;BR /&gt;
run;</description>
      <pubDate>Mon, 09 May 2011 10:01:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-table-using-arrays-from-data-on-2-other-tables/m-p/63012#M13695</guid>
      <dc:creator>exRhodesian</dc:creator>
      <dc:date>2011-05-09T10:01:48Z</dc:date>
    </item>
  </channel>
</rss>

