<?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 One-to-Many Merge in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/One-to-Many-Merge/m-p/820307#M323769</link>
    <description>&lt;P&gt;What modifications do I need to make to SAS procedures (i.e., proc surveyfreq, proc surveymean, proc surveylogistic) to accommodate a "long" data set that is the result of a one-to-many merge?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm merging 11 data sets from a complex survey. 10 of them have 1 observation per respondent. The 11th has multiple observations per respondent (Medications: 1 respondent could be taking multiple medications. Each medication is recorded as a separate observation for the same respondent ID).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I performed the merge using this syntax:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA work.data_2009_2010;
	MERGE 
	work.drug_use_2009_2010_sort 
	work.med_conds_2009_2010_cvd_sort 
	work.demos_2009_2010_sort 
	work.etoh_use_2009_2010_sort 
	work.smk_hx_2009_2010_sort 
	work.hdl_2009_2010_sort 
	work.tchol_2009_2010_sort 
	work.trigly_2009_2010_sort 
	work.bmx_2009_2010_sort 
	work.bpx_2009_2010_sort 
	work.rxq_rx_2009_2010_sort
	BY SEQN;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;When I perform a typical proc surveyfreq I see that multiple observations are used per respondent (see image). This overstates the number of events&amp;nbsp;(i.e., freq = 366)&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2022-06-24 at 12.02.46 PM.png" style="width: 532px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/72723i1DD3CD241F73698A/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screen Shot 2022-06-24 at 12.02.46 PM.png" alt="Screen Shot 2022-06-24 at 12.02.46 PM.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;This the syntax I am using:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc surveyfreq data=&amp;amp;dataset;
 	STRATUM sdmvstra;
 	CLUSTER sdmvpsu;
 	WEIGHT &amp;amp;weight;
 	
	table
/* 	flag_1*year */
	flag_1 /cl col chisq cellchi2 relrisk;
	;
	
	format 
	ever_told_mi 	yes_no_fmt.
	year 			yearfmt.
	&amp;amp;exp			cann_use_statusfmt.
	;
run; 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 24 Jun 2022 19:09:25 GMT</pubDate>
    <dc:creator>_maldini_</dc:creator>
    <dc:date>2022-06-24T19:09:25Z</dc:date>
    <item>
      <title>One-to-Many Merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/One-to-Many-Merge/m-p/820307#M323769</link>
      <description>&lt;P&gt;What modifications do I need to make to SAS procedures (i.e., proc surveyfreq, proc surveymean, proc surveylogistic) to accommodate a "long" data set that is the result of a one-to-many merge?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm merging 11 data sets from a complex survey. 10 of them have 1 observation per respondent. The 11th has multiple observations per respondent (Medications: 1 respondent could be taking multiple medications. Each medication is recorded as a separate observation for the same respondent ID).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I performed the merge using this syntax:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA work.data_2009_2010;
	MERGE 
	work.drug_use_2009_2010_sort 
	work.med_conds_2009_2010_cvd_sort 
	work.demos_2009_2010_sort 
	work.etoh_use_2009_2010_sort 
	work.smk_hx_2009_2010_sort 
	work.hdl_2009_2010_sort 
	work.tchol_2009_2010_sort 
	work.trigly_2009_2010_sort 
	work.bmx_2009_2010_sort 
	work.bpx_2009_2010_sort 
	work.rxq_rx_2009_2010_sort
	BY SEQN;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;When I perform a typical proc surveyfreq I see that multiple observations are used per respondent (see image). This overstates the number of events&amp;nbsp;(i.e., freq = 366)&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2022-06-24 at 12.02.46 PM.png" style="width: 532px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/72723i1DD3CD241F73698A/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screen Shot 2022-06-24 at 12.02.46 PM.png" alt="Screen Shot 2022-06-24 at 12.02.46 PM.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;This the syntax I am using:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc surveyfreq data=&amp;amp;dataset;
 	STRATUM sdmvstra;
 	CLUSTER sdmvpsu;
 	WEIGHT &amp;amp;weight;
 	
	table
/* 	flag_1*year */
	flag_1 /cl col chisq cellchi2 relrisk;
	;
	
	format 
	ever_told_mi 	yes_no_fmt.
	year 			yearfmt.
	&amp;amp;exp			cann_use_statusfmt.
	;
run; 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 24 Jun 2022 19:09:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/One-to-Many-Merge/m-p/820307#M323769</guid>
      <dc:creator>_maldini_</dc:creator>
      <dc:date>2022-06-24T19:09:25Z</dc:date>
    </item>
    <item>
      <title>Re: One-to-Many Merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/One-to-Many-Merge/m-p/820314#M323776</link>
      <description>&lt;P&gt;Looks like in way or another which ever set is the "many" you need to decide what you want and likely reduce it to a single observation prior to the merge. What and how, depends on what you need for analysis.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BTW you weighting variable is also now 'overweighting' any respondent that has multiple records in that many set unless the weight variable is designed for that many data set, which is unlikely.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jun 2022 20:16:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/One-to-Many-Merge/m-p/820314#M323776</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-06-24T20:16:47Z</dc:date>
    </item>
    <item>
      <title>Re: One-to-Many Merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/One-to-Many-Merge/m-p/820315#M323777</link>
      <description>&lt;P&gt;You modify your data, the procs do not handle this.&lt;/P&gt;
&lt;P&gt;Transpose the medication data set to a wide format before merging.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you're not familiar with data transposing, here are transposing data tutorials:&lt;BR /&gt;Long to Wide:&lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-long-to-wide-using-proc-transpose/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-long-to-wide-using-proc-transpose/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/modules/reshaping-data-long-to-wide-using-the-data-step/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/modules/reshaping-data-long-to-wide-using-the-data-step/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Wide to Long:&lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-wide-to-long-using-proc-transpose/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-wide-to-long-using-proc-transpose/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/modules/reshaping-data-wide-to-long-using-a-data-step/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/modules/reshaping-data-wide-to-long-using-a-data-step/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;And sometimes a double transpose is needed for extra wide data sets:&lt;BR /&gt;&lt;A href="https://gist.github.com/statgeek/2321b6f62ab78d5bf2b0a5a8626bd7cd" target="_blank"&gt;https://gist.github.com/statgeek/2321b6f62ab78d5bf2b0a5a8626bd7cd&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jun 2022 20:17:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/One-to-Many-Merge/m-p/820315#M323777</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-06-24T20:17:45Z</dc:date>
    </item>
  </channel>
</rss>

