<?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: SAS Merge in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-Merge/m-p/556656#M155084</link>
    <description>&lt;P&gt;Hi! Thanks so much for your quick input. I was looking at the want output and I was wondering how I could get the BMI values for both the rows and columns? Should I add a blank BMI column to and then merge and use your method? Thanks in advance!&lt;/P&gt;</description>
    <pubDate>Tue, 07 May 2019 14:35:34 GMT</pubDate>
    <dc:creator>serena13lee</dc:creator>
    <dc:date>2019-05-07T14:35:34Z</dc:date>
    <item>
      <title>SAS Merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Merge/m-p/556625#M155065</link>
      <description>&lt;P&gt;I am trying to merge two data sets in what I think is a one to many merge. It's a bit complex but I am trying to keep as much of Have1 because I have other calculations that depend on that dataset format. My goal is to get&amp;nbsp;Height1 Weight1 Head1 Feet1 BMI in the long format.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="sas"&gt;data have1;
input Patient $     Variable $   Value     Visit  $;
cards;
1 Height 1 a 
1 Weight 2 a 
1 Head 1 a 
1 Height 3 b
1 Weight 4 b
1 Head 5 b 
1 Feet 6 b
2 Height 3 c
2 Weight 2 c
2 Head 6 c
;&amp;lt;code&amp;gt;&amp;lt;/code&amp;gt;&amp;lt;code&amp;gt;&amp;lt;/code&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have2;
input Patient $ Visit $ Height1 Weight1 Head1 Feet1 BMI;
datalines;
1 a 1 2 1 . 5 
1 b 3 4 5 6 5
2 c 3 2 6 . 4
;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
input Patient $ Variable $ Value Visit $ Height1 Weight1 Head1 Feet1 BMI;
cards;
1 Height 1 a 1 . . . .
1 Weight 2 a . 2 . . .
1 Head 1 a . . 1 . .
1 BMI . a . . . . 5
1 Height 3 b 3 . . . .
1 Weight 4 b . 4 . . .
1 Head 5 b . . 5 . . 
1 Feet 6 b . . . 6 .
1 BMI . b . . . . 5
2 Height 3 c 3 . . . .                              
2 Weight 2 c . 2 . . . 
2 Head 6 c . . . 6 .
2 BMI . c . . . . 4                                              &amp;nbsp;
;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;In theory my attempt would be the following but I'm not sure how to get the BMI added to the Variable list:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
merge have1 have2;
by Patient Visit;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any insight would help! Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 07 May 2019 14:20:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Merge/m-p/556625#M155065</guid>
      <dc:creator>serena13lee</dc:creator>
      <dc:date>2019-05-07T14:20:30Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Merge/m-p/556630#M155068</link>
      <description>&lt;P&gt;Edit your original post with self-contained data steps.&amp;nbsp; Don't make us do your work by forcing us to convert your post into usable code.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 May 2019 02:13:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Merge/m-p/556630#M155068</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2019-05-07T02:13:17Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Merge/m-p/556636#M155072</link>
      <description>Hi Scott, I've added the data to hopefully be more readable. I haven't sure if it's correct since I don't have much experience in SAS but please let me know if that's so.</description>
      <pubDate>Tue, 07 May 2019 02:23:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Merge/m-p/556636#M155072</guid>
      <dc:creator>serena13lee</dc:creator>
      <dc:date>2019-05-07T02:23:50Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Merge/m-p/556638#M155074</link>
      <description>&lt;P&gt;It's nothing personal, there are just a lot of new users here that just whack any old data into the editor, then expect the respondent (eg. me) to get their data working &lt;U&gt;before I can even work on a solution&lt;/U&gt;.&amp;nbsp; I'm just over it, and won't contribute to those posts where I have to undertake more effort in getting the data working than the original poster bothered with.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As to your edits...nope, they don't work.&amp;nbsp; &lt;U&gt;&lt;STRONG&gt;Cut-and-paste&lt;/STRONG&gt;&lt;/U&gt; your code into SAS and get them to the point where the &lt;U&gt;cut-and-paste&lt;/U&gt; works without error.&amp;nbsp; Do this for both your source dataset(s) ("have(s)") and target results ("want").&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The "want" results allow us to run a proc compare on our results to easily tell if our results match your desired results.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you can't get that to work then you have bigger problems than how to format your question on these forums, and likely need to spend more time with the SAS documentation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also post your code as a SAS code block (the "running man" icon in the editor - it says "Insert SAS Code" when you hover over it).&lt;/P&gt;</description>
      <pubDate>Tue, 07 May 2019 02:42:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Merge/m-p/556638#M155074</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2019-05-07T02:42:59Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Merge/m-p/556641#M155075</link>
      <description>&lt;P&gt;P.S.:&amp;nbsp; Read the documentation on PROC TRANSPOSE.&lt;/P&gt;</description>
      <pubDate>Tue, 07 May 2019 02:37:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Merge/m-p/556641#M155075</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2019-05-07T02:37:23Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Merge/m-p/556645#M155076</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Have1 ;                              
input Patient Variable $ Value Visit  $;      
cards;
1       Height     1     a                 
1       Weight     2     a                  
1       Head       1     a    
1       Height     3     b
1       Weight     4     b
1       Head       5     b 
1       Feet       6     b
2       Height     3     c
2       Weight     2     c
2       Head       6     c
;

data Have2;
input Patient    Visit $  Height1  Weight1  Head1 Feet1    BMI;
cards;
1         a       1       2      1       .        5
1         b       3       4      5      6        5
2         c       3       2      6      .         4
;
data temp;
merge have1 have2;
by Patient Visit; 
run; 

data want;
set temp; 
array t(*) Height1--bmi;
do i=1 to dim(t);
k=strip(vname(t(i))) ;
if not index(k,strip(variable)) then call missing(t(I));
end;
drop k i;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 May 2019 03:10:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Merge/m-p/556645#M155076</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-05-07T03:10:30Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Merge/m-p/556649#M155080</link>
      <description>&lt;P&gt;Hi! Totally understand. I've updated the data so that it is readable. Please let me know if there's anything else I should edit.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 May 2019 03:28:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Merge/m-p/556649#M155080</guid>
      <dc:creator>serena13lee</dc:creator>
      <dc:date>2019-05-07T03:28:30Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Merge/m-p/556656#M155084</link>
      <description>&lt;P&gt;Hi! Thanks so much for your quick input. I was looking at the want output and I was wondering how I could get the BMI values for both the rows and columns? Should I add a blank BMI column to and then merge and use your method? Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Tue, 07 May 2019 14:35:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Merge/m-p/556656#M155084</guid>
      <dc:creator>serena13lee</dc:creator>
      <dc:date>2019-05-07T14:35:34Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Merge/m-p/556662#M155090</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/250829"&gt;@serena13lee&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;It's a bit complex but I am trying to keep as much of Have1 because I have other calculations that depend on that dataset format.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;I assume your 2nd "have1" is really your "want"?&amp;nbsp; (Minor:&amp;nbsp; also clean up your "want" proposed code).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;IMO that's a really strange format that I rarely see.&amp;nbsp; Can you give details on your "...other calculations that depend on that dataset format"?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Edit&lt;/STRONG&gt;:&amp;nbsp; My "gut feeling" is you want to store and process your data like this.&amp;nbsp; But without knowing the details of your "other calculations" I can't be sure.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Patient $     Variable $   Value     Visit  $;
cards;
1 Height 1 a 
1 Weight 2 a 
1 Head 1 a 
1 BMI 5 a  &amp;lt;&amp;lt;&amp;lt;
1 Height 3 b
1 Weight 4 b
1 Head 5 b 
1 Feet 6 b
1 BMI 5 b  &amp;lt;&amp;lt;&amp;lt;
2 Height 3 c
2 Weight 2 c
2 Head 6 c
2 BMI 4 c  &amp;lt;&amp;lt;&amp;lt;
;
run;

proc transpose data=have out=want;
   by patient visit;
   var value;
   id variable;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I'm also curious how you are creating your "have2" table?&lt;/P&gt;</description>
      <pubDate>Tue, 07 May 2019 04:47:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Merge/m-p/556662#M155090</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2019-05-07T04:47:32Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Merge/m-p/556683#M155100</link>
      <description>Hi Scott, thanks for the suggestion. For my "other calculations" I use them to create summary tables. For example, using Variable and Value, I can pull it into a macro and get a sum by each variable which is why I would still like to use that format later.&lt;BR /&gt;&lt;BR /&gt;As for my have2 table, it's a proc transpose of have1 essentially merged with a bmi column since I need that info.&lt;BR /&gt;&lt;BR /&gt;And yes I have edited it so that my 'want' output is more clear. Thanks.</description>
      <pubDate>Tue, 07 May 2019 07:40:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Merge/m-p/556683#M155100</guid>
      <dc:creator>serena13lee</dc:creator>
      <dc:date>2019-05-07T07:40:12Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Merge/m-p/556686#M155103</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;I use them to create summary tables. For example, using Variable and Value, I can pull it into a macro and get a sum by each variable&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Are you familiar with proc summary and BY group processing?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Post your macro and desired output from that macro.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;And yes I have edited it so that my 'want' output is more clear.&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;&amp;lt;br /&amp;gt;merge have1 have2;&amp;lt;br /&amp;gt;by Patient Visit;&amp;lt;br /&amp;gt;run;&amp;lt;code&amp;gt;&amp;lt;/code&amp;gt;&amp;lt;code&amp;gt;&amp;lt;/code&amp;gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Really?&amp;nbsp; (This is minor, just attention to detail.)&lt;/P&gt;</description>
      <pubDate>Tue, 07 May 2019 08:03:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Merge/m-p/556686#M155103</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2019-05-07T08:03:00Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Merge/m-p/556780#M155126</link>
      <description>Hi Scott! I am familiar with proc summary/by statements and unfortunately I cannot share my macro. It is a company internal macro but will not change the format that I need.</description>
      <pubDate>Tue, 07 May 2019 14:10:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Merge/m-p/556780#M155126</guid>
      <dc:creator>serena13lee</dc:creator>
      <dc:date>2019-05-07T14:10:07Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Merge/m-p/556793#M155131</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/250829"&gt;@serena13lee&lt;/a&gt;&amp;nbsp; &amp;nbsp;Try this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have1;
input Patient $     Variable $   Value     Visit  $;
cards;
1 Height 1 a 
1 Weight 2 a 
1 Head 1 a 
1 Height 3 b
1 Weight 4 b
1 Head 5 b 
1 Feet 6 b
2 Height 3 c
2 Weight 2 c
2 Head 6 c
;

data have2;
input Patient $ Visit $ Height1 Weight1 Head1 Feet1 BMI;
datalines;
1 a 1 2 1 . 5 
1 b 3 4 5 6 5
2 c 3 2 6 . 4
;
data temp;
merge have1 have2;
by Patient Visit; 
run; 
data bmi;
set have2;
keep patient visit bmi;
run;

data want;
set temp(drop=bmi) bmi(in=_bmi); 
by patient visit;
array t(*) Height1--Feet1;
do i=1 to dim(t);
k=strip(vname(t(i))) ;
if not index(k,strip(variable)) then call missing(t(I));
end;
if _bmi then variable='BMI';
drop k i;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 May 2019 14:47:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Merge/m-p/556793#M155131</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-05-07T14:47:24Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Merge/m-p/556801#M155134</link>
      <description>Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;,&lt;BR /&gt;Thanks so much for your solution! That was exactly what I was looking to do. The array I can see applied in many scenarios. It's very clean!</description>
      <pubDate>Tue, 07 May 2019 15:00:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Merge/m-p/556801#M155134</guid>
      <dc:creator>serena13lee</dc:creator>
      <dc:date>2019-05-07T15:00:13Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Merge/m-p/556803#M155135</link>
      <description>&lt;P&gt;You are welcome!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 May 2019 15:03:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Merge/m-p/556803#M155135</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-05-07T15:03:10Z</dc:date>
    </item>
  </channel>
</rss>

