<?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: Construct a dataset using information from two separate datasets in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Construct-a-dataset-using-information-from-two-separate-datasets/m-p/340184#M10094</link>
    <description>&lt;P&gt;I don't think I need to track the IDs.&amp;nbsp;&lt;/P&gt;&lt;P&gt;As long as the variables for&amp;nbsp;each ID enter into the corresponding columes for each observation in the final dataset, It is OK to not have IDs.&lt;/P&gt;&lt;P&gt;So the first three colums in the final dataset are the housing price, school quality, and share of greenspace for ID 92, because that is the first choice for observation 1, The 3-6 columns are housing price, school quality, and share of green space for ID 72 (the second choice for observation 1). The last three columns will be housing price, school quality, and share of green space for ID 54 for observation 1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 11 Mar 2017 20:08:55 GMT</pubDate>
    <dc:creator>Deester</dc:creator>
    <dc:date>2017-03-11T20:08:55Z</dc:date>
    <item>
      <title>Construct a dataset using information from two separate datasets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Construct-a-dataset-using-information-from-two-separate-datasets/m-p/340181#M10091</link>
      <description>&lt;P&gt;I have two datasets. One of the dataset contains&amp;nbsp;10 ID number for each observation (a total of 1000 observation). Hence the dataset is a 1000 by 10 matrix. Each ID number is an ID number for a location that contains&amp;nbsp;a set of information, such as housing price, school quality, share of green space. It looks like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; c1 &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;c2&amp;nbsp; &amp;nbsp; c3 &amp;nbsp; &amp;nbsp; c4 &amp;nbsp;... &amp;nbsp;c10 &amp;nbsp; &amp;nbsp; &amp;nbsp; (columes are 10 IDs corresponding to each observations)&lt;/P&gt;&lt;P&gt;obs1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;91 &amp;nbsp; &amp;nbsp; &amp;nbsp;72 &amp;nbsp; &amp;nbsp; &amp;nbsp;4 &amp;nbsp; &amp;nbsp; 87 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 54&lt;/P&gt;&lt;P&gt;obs2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;34 &amp;nbsp; &amp;nbsp; &amp;nbsp;76 &amp;nbsp; &amp;nbsp; 95 &amp;nbsp; &amp;nbsp; 8 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 100&lt;/P&gt;&lt;P&gt;:&lt;/P&gt;&lt;P&gt;:&lt;/P&gt;&lt;P&gt;obs1000 &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3 &amp;nbsp; &amp;nbsp; &amp;nbsp;90 &amp;nbsp; &amp;nbsp; 78 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;64&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Another dataset has all the information for all the locations (ID is the indicator which location it is). The dataset looks like:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;housing price &amp;nbsp; &amp;nbsp; &amp;nbsp;school quality index &amp;nbsp; &amp;nbsp;share of greenspace&lt;/P&gt;&lt;P&gt;id1 &amp;nbsp; &amp;nbsp;1000,000,000 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 50%&lt;/P&gt;&lt;P&gt;id2 &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;:&lt;/P&gt;&lt;P&gt;:&lt;/P&gt;&lt;P&gt;id100 &amp;nbsp; 40,000,000 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;15%&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to construct a unified dataset by combining information from the two datasets. It will look like:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; housing price &amp;nbsp; &amp;nbsp; school quaility index &amp;nbsp; &amp;nbsp; share of greenspace &amp;nbsp;| &amp;nbsp;&amp;nbsp;&lt;SPAN&gt;housing price &amp;nbsp; &amp;nbsp; school quaility index &amp;nbsp; &amp;nbsp; share of greenspace&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;obs1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;info for location with ID91 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;info for location with ID72&lt;/P&gt;&lt;P&gt;obs2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;SPAN&gt;info for location with ID34 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;info for location with ID76&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;:&lt;/P&gt;&lt;P&gt;:&lt;/P&gt;&lt;P&gt;obs100&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Therefore the final dataset is a 100 (number of observation) by 10 (10 ID for each observation )*3 (number of variables correspond to each ID) matrix.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am having trouble to find a way to achieve the final goal. Any help will be much appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!!&lt;/P&gt;</description>
      <pubDate>Sat, 11 Mar 2017 19:26:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Construct-a-dataset-using-information-from-two-separate-datasets/m-p/340181#M10091</guid>
      <dc:creator>Deester</dc:creator>
      <dc:date>2017-03-11T19:26:27Z</dc:date>
    </item>
    <item>
      <title>Re: Construct a dataset using information from two separate datasets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Construct-a-dataset-using-information-from-two-separate-datasets/m-p/340182#M10092</link>
      <description>&lt;P&gt;Transpose dataset1 to a long format and then join it to the second dataset. You can then make it wide again with a transpose, but the long format is likely to be more useful.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use PROC TRANSPOSE to flip the datasets.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 11 Mar 2017 19:48:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Construct-a-dataset-using-information-from-two-separate-datasets/m-p/340182#M10092</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-03-11T19:48:53Z</dc:date>
    </item>
    <item>
      <title>Re: Construct a dataset using information from two separate datasets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Construct-a-dataset-using-information-from-two-separate-datasets/m-p/340183#M10093</link>
      <description>&lt;P&gt;Actually, sounds like you want a 1000 X 10 X 4&amp;nbsp;matrix .. unless you don't need to keep track of the IDs in which case it would be a 1000 X 10 X3 matrix. &amp;nbsp;Are you sure that's what you want? Do you need to keep track of the&amp;nbsp;IDs?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 11 Mar 2017 19:53:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Construct-a-dataset-using-information-from-two-separate-datasets/m-p/340183#M10093</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-03-11T19:53:54Z</dc:date>
    </item>
    <item>
      <title>Re: Construct a dataset using information from two separate datasets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Construct-a-dataset-using-information-from-two-separate-datasets/m-p/340184#M10094</link>
      <description>&lt;P&gt;I don't think I need to track the IDs.&amp;nbsp;&lt;/P&gt;&lt;P&gt;As long as the variables for&amp;nbsp;each ID enter into the corresponding columes for each observation in the final dataset, It is OK to not have IDs.&lt;/P&gt;&lt;P&gt;So the first three colums in the final dataset are the housing price, school quality, and share of greenspace for ID 92, because that is the first choice for observation 1, The 3-6 columns are housing price, school quality, and share of green space for ID 72 (the second choice for observation 1). The last three columns will be housing price, school quality, and share of green space for ID 54 for observation 1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 11 Mar 2017 20:08:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Construct-a-dataset-using-information-from-two-separate-datasets/m-p/340184#M10094</guid>
      <dc:creator>Deester</dc:creator>
      <dc:date>2017-03-11T20:08:55Z</dc:date>
    </item>
    <item>
      <title>Re: Construct a dataset using information from two separate datasets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Construct-a-dataset-using-information-from-two-separate-datasets/m-p/340185#M10095</link>
      <description>&lt;P&gt;After transpose data1 from wide to long format, each column has 10 IDs an observation chooses. The 10 IDs are randomly chosen&amp;nbsp;from 1 to 100 IDs in the second datasets.&lt;/P&gt;&lt;P&gt;So if I want to merge the first dataset with the second dataset, I need to do it for each column.&lt;/P&gt;&lt;P&gt;That might work.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 11 Mar 2017 20:19:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Construct-a-dataset-using-information-from-two-separate-datasets/m-p/340185#M10095</guid>
      <dc:creator>Deester</dc:creator>
      <dc:date>2017-03-11T20:19:32Z</dc:date>
    </item>
    <item>
      <title>Re: Construct a dataset using information from two separate datasets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Construct-a-dataset-using-information-from-two-separate-datasets/m-p/340186#M10096</link>
      <description>&lt;P&gt;Not sure what you are trying to do regarding the random selection part. Since I've never liked doing double transposes (which is what you have to do to get from wide to wider), I always do that kind of transposition with the macro you can download for free at:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://www.sascommunity.org/wiki/A_Better_Way_to_Flip_(Transpose)_a_SAS_Dataset" target="_blank"&gt;http://www.sascommunity.org/wiki/A_Better_Way_to_Flip_(Transpose)_a_SAS_Dataset&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That said, while I only tested this on a 5 id case (like you presented data for in your example), the following appears to do what you want:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data obs;
  input obs id1-id5;
  cards;
1          91      72      4     87         54
2          34      76     95     8         100
1000    1         3      90     78        64
;

proc transpose data=obs out=tobs (rename=(col1=id));
  var id1-id5;
  by obs;
run;

data tobs (drop=_:);
  set tobs;
  pref=input(substr(_name_,3),8.);
run;

data locs;
  input id housing_price school_quality_index    share_of_greenspace;
  cards;
91    1000000000                  2                               50
4      150000000               1                                35
76   40000000                  5                                15
;

proc sql;
  create table need as
    select * from
      tobs a
        left join
          locs b
            on a.id eq b.id
              order by obs,pref
  ;
quit;

%transpose(data=need, out=want, by=obs, id=pref, guessingrows=1000,
 delimiter=_, var=housing_price school_quality_index share_of_greenspace)
&lt;/PRE&gt;
&lt;P&gt;HTH,&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 11 Mar 2017 20:31:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Construct-a-dataset-using-information-from-two-separate-datasets/m-p/340186#M10096</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-03-11T20:31:47Z</dc:date>
    </item>
    <item>
      <title>Re: Construct a dataset using information from two separate datasets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Construct-a-dataset-using-information-from-two-separate-datasets/m-p/340187#M10097</link>
      <description>&lt;P&gt;Thank you very much Art! I will try it out and see how it&amp;nbsp;works out!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 11 Mar 2017 20:35:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Construct-a-dataset-using-information-from-two-separate-datasets/m-p/340187#M10097</guid>
      <dc:creator>Deester</dc:creator>
      <dc:date>2017-03-11T20:35:53Z</dc:date>
    </item>
    <item>
      <title>Re: Construct a dataset using information from two separate datasets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Construct-a-dataset-using-information-from-two-separate-datasets/m-p/340210#M10098</link>
      <description>&lt;P&gt;Thank you Art. Your method worked.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I really appreciate your help!!!&lt;/P&gt;</description>
      <pubDate>Sun, 12 Mar 2017 03:15:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Construct-a-dataset-using-information-from-two-separate-datasets/m-p/340210#M10098</guid>
      <dc:creator>Deester</dc:creator>
      <dc:date>2017-03-12T03:15:31Z</dc:date>
    </item>
  </channel>
</rss>

