<?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: Merging Multiple Datasets to One Dataset in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Merging-Multiple-Datasets-to-One-Dataset/m-p/723424#M27968</link>
    <description>&lt;P&gt;As discussed in &lt;A href="https://communities.sas.com/t5/New-SAS-User/How-to-Sum-Multiple-Columns-By-Unique-Identifier-with-Dynamic/m-p/723085#M27935" target="_self"&gt;your other thread&lt;/A&gt;, creating a long instead of wide data set is the way to go. Don't make the mistake of insisting on a wide data set, this makes your programming more difficult. A long data set, as shown in your other thread, is much easier to work with.&lt;/P&gt;</description>
    <pubDate>Thu, 04 Mar 2021 11:46:15 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2021-03-04T11:46:15Z</dc:date>
    <item>
      <title>Merging Multiple Datasets to One Dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Merging-Multiple-Datasets-to-One-Dataset/m-p/723340#M27963</link>
      <description>&lt;P&gt;Hi all&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have multiple datasets named after stock tickers: AAPL AMZN MSFT etc. I have about 1000 and I want to merge them all into one data file. Each dataset is set up with the same columns: date&amp;amp;time date hour minute holding_"ticker" (e.g. holding_aapl). I want my new dataset to have the columns: date&amp;amp;time date hour minute holding_aapl holding_amzn holding_msft etc. This is the code I have so far:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql ;&lt;BR /&gt;create table WORK.mytables as&lt;BR /&gt;select*&lt;BR /&gt;from dictionary.tables&lt;BR /&gt;where libname = 'WORK'&lt;BR /&gt;order by memname ;&lt;BR /&gt;quit ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro mergedata;&lt;BR /&gt;proc sql ;&lt;BR /&gt;select count(memname) into: obs from work.mytables;&lt;/P&gt;&lt;P&gt;%LET OBS=&amp;amp;OBS.;&lt;/P&gt;&lt;P&gt;%let obs=&amp;amp;obs.;&lt;BR /&gt;SELECT CATX("test", memname)&lt;BR /&gt;INTO :SETNAME1-:SETNAME&amp;amp;OBS.&lt;BR /&gt;FROM work.MYTABLES;&lt;BR /&gt;QUIT;&lt;/P&gt;&lt;P&gt;%DO i=1 %to &amp;amp;obs.;&lt;BR /&gt;data merged;&lt;BR /&gt;merge work.aapl (in=ina)&lt;BR /&gt;work.&amp;amp;&amp;amp;setname&amp;amp;i (in=inb);&lt;BR /&gt;by date hour dummy;&lt;BR /&gt;if ina;&lt;BR /&gt;run;&lt;BR /&gt;proc append data=merged base=work.merged;&lt;BR /&gt;run;&lt;BR /&gt;%end;&lt;BR /&gt;%mend;&lt;BR /&gt;%mergedata;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But the new merge keeps replacing the old merge so I am left with a dataset that has date&amp;amp;time date hour minute holding_aapl holding_msft or whichever the last chronological stock is. I tried it without the proc append line and still overwriting it. Any help would be much appreiated!&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 01:42:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Merging-Multiple-Datasets-to-One-Dataset/m-p/723340#M27963</guid>
      <dc:creator>MellyJ13</dc:creator>
      <dc:date>2021-03-04T01:42:51Z</dc:date>
    </item>
    <item>
      <title>Re: Merging Multiple Datasets to One Dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Merging-Multiple-Datasets-to-One-Dataset/m-p/723343#M27964</link>
      <description>&lt;P&gt;I don't think you want a data step merge, that is side by side and replaces values of like named variables.&lt;/P&gt;
&lt;P&gt;It sounds like you want an Append&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Simplest sounds like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want;
    set aapl amzn msft &amp;lt;continue the list&amp;gt;;
   keep &amp;lt;the list of common variables goes here&amp;gt;;
run;&lt;/PRE&gt;
&lt;P&gt;If this doesn't work then provide some details why not.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 02:15:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Merging-Multiple-Datasets-to-One-Dataset/m-p/723343#M27964</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-03-04T02:15:40Z</dc:date>
    </item>
    <item>
      <title>Re: Merging Multiple Datasets to One Dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Merging-Multiple-Datasets-to-One-Dataset/m-p/723345#M27965</link>
      <description>&lt;P&gt;I do want it to be side by side. I might be using the proc append function incorrectly. In the final dataset I want to have all the tickers as individual columns:&lt;/P&gt;&lt;P&gt;DATE&amp;amp;TIME DATE HOUR MINUTE HOLDING_AAPL HOLDING AMZN ------- HOLDING_LUV --------HOLDING_MSFT etc.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 02:39:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Merging-Multiple-Datasets-to-One-Dataset/m-p/723345#M27965</guid>
      <dc:creator>MellyJ13</dc:creator>
      <dc:date>2021-03-04T02:39:04Z</dc:date>
    </item>
    <item>
      <title>Re: Merging Multiple Datasets to One Dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Merging-Multiple-Datasets-to-One-Dataset/m-p/723349#M27966</link>
      <description>&lt;P&gt;Why do you want it side by side?&amp;nbsp; &amp;nbsp;Is this because each has an identical sequences of data &amp;amp; time?&amp;nbsp; Are you trying to determine some sort of portfolio value over the time series?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it is really a matter of synchronized time series, you would almost certainly be better off interleaving the series, i.e. N(stocks) records for time point 1 followed by N(stocks) records for time point 2, etc.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;More context please.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 03:13:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Merging-Multiple-Datasets-to-One-Dataset/m-p/723349#M27966</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-03-04T03:13:39Z</dc:date>
    </item>
    <item>
      <title>Re: Merging Multiple Datasets to One Dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Merging-Multiple-Datasets-to-One-Dataset/m-p/723350#M27967</link>
      <description>&lt;P&gt;You originally said the files all had the same structure. How are you going to create NEW variables?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your description of the variable names is also very confusing.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;date&amp;amp;time date hour minute holding_"ticker"&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Do you really have a variable name with an &amp;amp; in it?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why do you have DATE twice? Why do you have TIME and HOUR and MINUTE?&amp;nbsp; &amp;nbsp;Is the first variable really the just the same information as the next three?&lt;/P&gt;
&lt;P&gt;Does that last variable name really have quotes in it?&amp;nbsp; Perhaps you mean to say that the last variable has a different name in each of the source datasets?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are the original datasets sorted by the DATETIME?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why is your attempt to merge only using DATE HOUR?&amp;nbsp; Are you trying to collapse multiple minute level observations into a single observation for the hour?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please post a few observations of at least two of the datasets and show what output dataset you want for the posted example input.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 03:20:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Merging-Multiple-Datasets-to-One-Dataset/m-p/723350#M27967</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-03-04T03:20:35Z</dc:date>
    </item>
    <item>
      <title>Re: Merging Multiple Datasets to One Dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Merging-Multiple-Datasets-to-One-Dataset/m-p/723424#M27968</link>
      <description>&lt;P&gt;As discussed in &lt;A href="https://communities.sas.com/t5/New-SAS-User/How-to-Sum-Multiple-Columns-By-Unique-Identifier-with-Dynamic/m-p/723085#M27935" target="_self"&gt;your other thread&lt;/A&gt;, creating a long instead of wide data set is the way to go. Don't make the mistake of insisting on a wide data set, this makes your programming more difficult. A long data set, as shown in your other thread, is much easier to work with.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 11:46:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Merging-Multiple-Datasets-to-One-Dataset/m-p/723424#M27968</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-03-04T11:46:15Z</dc:date>
    </item>
  </channel>
</rss>

