<?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: One-to-many Merge with a Twist in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/One-to-many-Merge-with-a-Twist/m-p/446081#M111867</link>
    <description>&lt;P&gt;As long as you can be sure that there's always four entries in A for every entry in B, then this will do it:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set b;
do i = 1 to 4;
  set a;
  output;
end;
drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;A more robust version uses transpose:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data int1;
set a;
by id;
if first.id then visit = 0;
if test = 'a' then visit + 1;
run;

proc transpose data=int1 out=int2 (drop=_name_);
var sev;
id test;
by id visit;
run;

data int3;
set b;
by id;
if first.id
then visit = 1;
else visit + 1;
run;

data int4;
merge
  int2
  int3
;
by id visit;
run;

data want (keep=id test sev date);
set int4;
array vars {4} a b c d;
do i = 1 to 4;
  test = vname(vars{i});
  sev = vars{i};
  output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 16 Mar 2018 06:37:34 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2018-03-16T06:37:34Z</dc:date>
    <item>
      <title>One-to-many Merge with a Twist</title>
      <link>https://communities.sas.com/t5/SAS-Programming/One-to-many-Merge-with-a-Twist/m-p/446079#M111865</link>
      <description>&lt;P&gt;&amp;nbsp;i am attached sas editor file below&lt;BR /&gt;Every id visit in three times each visit conduct four test a b c d in every vist&lt;BR /&gt;and second data "b"&amp;nbsp; give three vist of date.&lt;BR /&gt;how merge date varable of data b&amp;nbsp; with data a dataset.&lt;BR /&gt;i want like this&lt;BR /&gt;1 a 1 aa&lt;BR /&gt;1 b 2 aa&lt;BR /&gt;1 c 1 aa&lt;BR /&gt;1 d 1 aa&lt;BR /&gt;1 a . bb&lt;BR /&gt;1 b 2 bb&lt;BR /&gt;1 c . bb&lt;BR /&gt;1 d 2 bb&lt;BR /&gt;.... like this;&lt;BR /&gt;data a;&lt;BR /&gt;input id test$ sev @@;&lt;BR /&gt;datalines;&lt;BR /&gt;1 a 1 1 b 2 1 c 1 1 d 1&lt;BR /&gt;1 a . 1 b 2 1 c . 1 d 2&lt;BR /&gt;1 a 2 1 b 2 1 c 1 1 d 1&lt;BR /&gt;2 a 1 2 b . 2 c 1 2 d 2&lt;BR /&gt;2 a 1 2 b 1 2 c . 2 d 2&lt;BR /&gt;2 a 2 2 b 1 2 c 1 2 d 1&lt;BR /&gt;3 a 1 3 b 1 3 c 1 3 d 2&lt;BR /&gt;3 a 2 3 b 2 3 c 2 3 d 1&lt;BR /&gt;3 a . 3 b 1 3 c 1 3 d 2&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data b;&lt;BR /&gt;input id date$ @@;&lt;BR /&gt;datalines;&lt;BR /&gt;1 aa 1 bb 1 cc&lt;BR /&gt;2 dd 2 ee 2 ff&lt;BR /&gt;3 ee 3 gg 3 df&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Mar 2018 06:37:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/One-to-many-Merge-with-a-Twist/m-p/446079#M111865</guid>
      <dc:creator>rvsidhu035</dc:creator>
      <dc:date>2018-03-16T06:37:16Z</dc:date>
    </item>
    <item>
      <title>Re: One-to-many Merge with a Twist</title>
      <link>https://communities.sas.com/t5/SAS-Programming/One-to-many-Merge-with-a-Twist/m-p/446081#M111867</link>
      <description>&lt;P&gt;As long as you can be sure that there's always four entries in A for every entry in B, then this will do it:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set b;
do i = 1 to 4;
  set a;
  output;
end;
drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;A more robust version uses transpose:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data int1;
set a;
by id;
if first.id then visit = 0;
if test = 'a' then visit + 1;
run;

proc transpose data=int1 out=int2 (drop=_name_);
var sev;
id test;
by id visit;
run;

data int3;
set b;
by id;
if first.id
then visit = 1;
else visit + 1;
run;

data int4;
merge
  int2
  int3
;
by id visit;
run;

data want (keep=id test sev date);
set int4;
array vars {4} a b c d;
do i = 1 to 4;
  test = vname(vars{i});
  sev = vars{i};
  output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 16 Mar 2018 06:37:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/One-to-many-Merge-with-a-Twist/m-p/446081#M111867</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-03-16T06:37:34Z</dc:date>
    </item>
  </channel>
</rss>

