<?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: Merge datasets in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Merge-datasets/m-p/938390#M368592</link>
    <description />
    <pubDate>Tue, 06 Aug 2024 17:01:21 GMT</pubDate>
    <dc:creator>lu_king</dc:creator>
    <dc:date>2024-08-06T17:01:21Z</dc:date>
    <item>
      <title>Merge datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-datasets/m-p/938389#M368591</link>
      <description>Hi all!&lt;BR /&gt;&lt;BR /&gt;I have two datasets, but I want P1/P2 variable name in dataset B and it’s value to merge under the Target variable name and GcL1000 respectively in dataset A. How can I do this?&lt;BR /&gt;&lt;BR /&gt;For example,&lt;BR /&gt;Dataset A&lt;BR /&gt;Date location target gcl gcl1000&lt;BR /&gt;25 Ab P1 .04 4.00&lt;BR /&gt;25 Ab P2 2.8 28.00&lt;BR /&gt;25 An P1 46.99 788.00&lt;BR /&gt;25 An P2 67.99 36.00&lt;BR /&gt;&lt;BR /&gt;Data set B&lt;BR /&gt;Date location P1/P2&lt;BR /&gt;25 Ab 450.098&lt;BR /&gt;25 An 4774.995&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;The goal dataset would look something like this:&lt;BR /&gt;&lt;BR /&gt;Date location target gcl gcl1000&lt;BR /&gt;25 Ab P1 .04 4.00&lt;BR /&gt;25 Ab P2 2.8 28.00&lt;BR /&gt;25 An P1 46.99 788.00&lt;BR /&gt;25 An P2 67.99 36.00&lt;BR /&gt;25 Ab P1/P2 450.098&lt;BR /&gt;25 An P1/P2 4774.995</description>
      <pubDate>Tue, 06 Aug 2024 17:07:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-datasets/m-p/938389#M368591</guid>
      <dc:creator>lu_king</dc:creator>
      <dc:date>2024-08-06T17:07:08Z</dc:date>
    </item>
    <item>
      <title>Re: Merge datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-datasets/m-p/938390#M368592</link>
      <description />
      <pubDate>Tue, 06 Aug 2024 17:01:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-datasets/m-p/938390#M368592</guid>
      <dc:creator>lu_king</dc:creator>
      <dc:date>2024-08-06T17:01:21Z</dc:date>
    </item>
    <item>
      <title>Re: Merge datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-datasets/m-p/938391#M368593</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/437638"&gt;@lu_king&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Edit: I want P1/P2 to merge under Target in dataset A!&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;No idea what you mean by "merge under".&amp;nbsp; In SAS you merge BY some set of variables.&amp;nbsp; So observations that match on the variables get merged into a single observation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perhaps by "under" you mean after?&amp;nbsp; Perhaps instead of merging the dataset you just want to set them together?&amp;nbsp; In that case you can use a BY statement to interleave the observation by the ID variables.&amp;nbsp; The observations from the dataset listed last will appear "under" the observations for the other datasets within that set of BY values.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Aug 2024 16:59:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-datasets/m-p/938391#M368593</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-08-06T16:59:25Z</dc:date>
    </item>
    <item>
      <title>Re: Merge datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-datasets/m-p/938392#M368594</link>
      <description>&lt;P&gt;Please show us the desired output table.&amp;nbsp;Honestly, I'm lost trying to follow your description of what you want.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Aug 2024 16:59:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-datasets/m-p/938392#M368594</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-08-06T16:59:27Z</dc:date>
    </item>
    <item>
      <title>Re: Merge datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-datasets/m-p/938395#M368596</link>
      <description>&lt;P&gt;Please post both datasets as&amp;nbsp;&lt;U&gt;working&lt;/U&gt; DATA steps with DATALINES.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is the real name of that "P1/P2" variable? And into which variable of dataset A should these values be stored?&lt;/P&gt;</description>
      <pubDate>Tue, 06 Aug 2024 17:21:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-datasets/m-p/938395#M368596</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-08-06T17:21:31Z</dc:date>
    </item>
    <item>
      <title>Re: Merge datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-datasets/m-p/938398#M368597</link>
      <description>data datasetA;&lt;BR /&gt;input Date $ Location $ Target $ gcl gcl1000;&lt;BR /&gt;datalines;&lt;BR /&gt;25 Ab P1 0.04 4.00&lt;BR /&gt;25 Ab P2 2.8 28.00&lt;BR /&gt;25 An P1 46.99 788.00&lt;BR /&gt;25 An P2 67.99 36.00&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data datasetB;&lt;BR /&gt;input Date $ Location $ P1_P2 $;&lt;BR /&gt;datalines;&lt;BR /&gt;25 Ab 450.098&lt;BR /&gt;25 An 4774.995&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;The real name of P1/P2 is P1_P2, they’re protein locations that I’m averaging together. I’d like them to be stored under the Target variable in dataset A.&lt;BR /&gt;&lt;BR /&gt;So that it reads in the merged dataset as follows&lt;BR /&gt;&lt;BR /&gt;Data mergeddata;&lt;BR /&gt;input Date $ Location $ Target $ gcl gcl1000;&lt;BR /&gt;datalines;&lt;BR /&gt;25 Ab P1 0.04 4.00&lt;BR /&gt;25 Ab P2 2.8 28.00&lt;BR /&gt;25 An P1 46.99 788.00&lt;BR /&gt;25 An P2 67.99 36.00&lt;BR /&gt;25 Ab P1/P2 450.098&lt;BR /&gt;25 An P1/P2 4774.995&lt;BR /&gt;;&lt;BR /&gt;run;</description>
      <pubDate>Tue, 06 Aug 2024 18:14:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-datasets/m-p/938398#M368597</guid>
      <dc:creator>lu_king</dc:creator>
      <dc:date>2024-08-06T18:14:58Z</dc:date>
    </item>
    <item>
      <title>Re: Merge datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-datasets/m-p/938448#M368618</link>
      <description>&lt;P&gt;So if you actually MERGE the two datasets:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data datasetA;
  input Date $ Location $ Target $ gcl gcl1000;
datalines;
25 Ab P1 0.04 4.00
25 Ab P2 2.8 28.00
25 An P1 46.99 788.00
25 An P2 67.99 36.00
;

data datasetB;
  input Date $ Location $ P1_P2 ;
datalines;
25 Ab 450.098
25 An 4774.995
;

data want;
  merge datasetA datasetB ;
  by date location ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You will get this dataset:&lt;/P&gt;
&lt;PRE&gt;Obs    Date    Location    Target     gcl     gcl1000     P1_P2

 1      25        Ab         P1       0.04        4       450.10
 2      25        Ab         P2       2.80       28       450.10
 3      25        An         P1      46.99      788      4775.00
 4      25        An         P2      67.99       36      4775.00
&lt;/PRE&gt;
&lt;P&gt;What you propose as your desired output does not look like a DATASET.&amp;nbsp; And the code you posted cannot run.&lt;/P&gt;
&lt;PRE&gt;NOTE: SAS went to a new line when INPUT statement reached past the end of a line
&lt;/PRE&gt;
&lt;P&gt;If you just STACK the datasets:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want2;
  set datasetA datasetB ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can get something very similar to what I assume you wanted.&lt;/P&gt;
&lt;PRE&gt;Obs    Date    Location    Target     gcl     gcl1000     P1_P2

 1      25        Ab         P1       0.04        4          .
 2      25        Ab         P2       2.80       28          .
 3      25        An         P1      46.99      788          .
 4      25        An         P2      67.99       36          .
 5      25        Ab                   .          .       450.10
 6      25        An                   .          .      4775.00
&lt;/PRE&gt;
&lt;P&gt;It would not be that hard to change the value of TARGET to P1/P2 in those last two observations.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want2;
  set datasetA datasetB (in=inb);
  if inb then target='P1/P2';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But I have no idea where you want to put the value of P1_P2 other than where it already is.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Aug 2024 23:42:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-datasets/m-p/938448#M368618</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-08-06T23:42:58Z</dc:date>
    </item>
    <item>
      <title>Re: Merge datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-datasets/m-p/938471#M368625</link>
      <description>&lt;P&gt;This should lead to your desired result:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set
  dataseta
  datasetb (
    in=inb
    rename=(p1_p2=gcl)
  )
;
by date location;
if inb then target = "P1/P2";
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Please test your codes before posting them; it's a matter of base courtesy.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Aug 2024 06:44:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-datasets/m-p/938471#M368625</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-08-07T06:44:15Z</dc:date>
    </item>
  </channel>
</rss>

