<?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: Match-Merge Data Sets in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Match-Merge-Data-Sets/m-p/703997#M215770</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/349689"&gt;@adhunamukherjee&lt;/a&gt;&amp;nbsp;With that kind of data, it's probably easier to merge numeric values.&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;if ID = input(compress(CHAR,,'dk'),10.);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 06 Dec 2020 23:17:55 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2020-12-06T23:17:55Z</dc:date>
    <item>
      <title>Match-Merge Data Sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Match-Merge-Data-Sets/m-p/703955#M215751</link>
      <description>&lt;P&gt;Hi SAS communities,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am currently trying to match merge 4 data sets into one. There should only be 1 observations per person, which includes the most recent visit. The data set should include people that have data in the 3 data sets: Contact, Demog, and Vitals. Also, most of the people in those data sets have not died and will not have a matching observation in the NDI data set.&amp;nbsp; Conversely, most of the people in the ‘NDI’ data set are not in our cohort (so we don’t want to include those observations).&amp;nbsp; Therefore, when performing a match-merge with the ‘NDI’ data set, the observations from the ‘NDI’ data set which don’t have a matching row in the other 3 data sets should not be included.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA HYPANL.HYPANALYSIS2;
	RETAIN SSN StateCd GenderCd EthCd RaceCd AgeAtVisit SBP DBP WtLb HypRelDeathInd;
	MERGE 	WORK.VitalLast		(IN = InVitalLast)
			HypTabs.NDI 		(IN = InNDI)
			HypTabs.Contact 	(IN = InContact)
			HypTabs.DEMOG 		(IN = InDemog);
	BY SSN;
	IF 	InContact 		= 1 
		AND InVitalLast = 1 
		AND InDemog 	= 1;
		
		
/* 	IF LAST.SSN; */
	AgeAtVisit=yrdif(BirthDt, VisitDt, 'AGE');	
	FORMAT 	BirthDt YYMMDD10.
			AgeAtVisit 4.0;
			
/* 		IF InNDI = 0 THEN HypRelDeathInd = 0;		 */
/* 	IF InNDI = . 		THEN HypRelDeathInd = 0; */
/* 	ELSE IF InNDI = 0 	THEN HypRelDeathInd = 0; */
/* 	ELSE IF InNDI = 1 	THEN HypRelDeathInd = 1; */

	IF HypRelDeathInd = . 		THEN HypRelDeathInd = 0;
/* 	ELSE IF HypRelDeathInd = 0 	THEN HypRelDeathInd = 0; */
/* 	ELSE 							 HypRelDeathInd = 1; */

	FORMAT 	HypRelDeathInd 	IndVbl. 
			StateCd 		$StateCd.;

	FORMAT HypRelDeathInd IndVbl. StateCd $StateCd.;
	DROP VisitDt HtIn DeathDt ICD10 CODCd City Inits ZipCd EthRaceCd BirthDt;
RUN;
PROC PRINT DATA = HYPANL.HYPANALYSIS2;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I have tried several IF THEN statements, but I still get 566 observations. However, with some IF THEN statements I get 11 observations that have a 'Yes' in the 'HypRelDeathInd' variable, and with other IF THEN statements I get 16. Either way, I still end up with 566 observations, which means there are 7 missing observations.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance for any help/tips!&lt;/P&gt;</description>
      <pubDate>Sun, 06 Dec 2020 20:03:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Match-Merge-Data-Sets/m-p/703955#M215751</guid>
      <dc:creator>mdakkak</dc:creator>
      <dc:date>2020-12-06T20:03:32Z</dc:date>
    </item>
    <item>
      <title>Re: Match-Merge Data Sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Match-Merge-Data-Sets/m-p/703959#M215753</link>
      <description>&lt;P&gt;Have you tried using the YDRIF statement?&lt;BR /&gt;&lt;BR /&gt;AgeAtVisit = YRDIF(BirthDt, VisitDt, 'Age');&lt;BR /&gt;FORMAT AgeAtVisit 2.0;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Dec 2020 15:19:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Match-Merge-Data-Sets/m-p/703959#M215753</guid>
      <dc:creator>bhufman</dc:creator>
      <dc:date>2020-12-10T15:19:07Z</dc:date>
    </item>
    <item>
      <title>Re: Match-Merge Data Sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Match-Merge-Data-Sets/m-p/703960#M215754</link>
      <description>&lt;P&gt;I haven't studied your code, but note that NONE of the in dummies (InVitalLast InNDI InContact InDemog) will ever&amp;nbsp;have a missing value.&amp;nbsp; They will be either zero or one.&lt;/P&gt;</description>
      <pubDate>Sun, 06 Dec 2020 20:59:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Match-Merge-Data-Sets/m-p/703960#M215754</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-12-06T20:59:36Z</dc:date>
    </item>
    <item>
      <title>Re: Match-Merge Data Sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Match-Merge-Data-Sets/m-p/703968#M215761</link>
      <description>&lt;P&gt;&lt;EM&gt;&amp;gt;&amp;nbsp;The data set should include people that have data in the 3 data sets: Contact, Demog, and Vitals&amp;nbsp; &amp;nbsp;... 8&amp;gt;&amp;lt; ...&amp;nbsp; the observations from the ‘NDI’ data set which don’t have a matching row in the other 3 data sets should not be included.&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Surely this clause you wrote implements&amp;nbsp;all these criteria?&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE class="language-sas"&gt;&lt;CODE&gt;	IF 	InContact 		= 1 
		AND InVitalLast = 1 
		AND InDemog 	= 1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&amp;gt; I have tried several IF THEN statements, but I still get 566 observations. However, with some IF THEN statements I get 11 observations that have a 'Yes' in the 'HypRelDeathInd' variable, and with other IF THEN statements I get 16. Either way, I still end up with 566 observations, which means there are 7 missing observations.&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I have no idea what you are after. Provide some sample data?&amp;nbsp;&lt;/SPAN&gt;&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;</description>
      <pubDate>Sun, 06 Dec 2020 21:23:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Match-Merge-Data-Sets/m-p/703968#M215761</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-12-06T21:23:55Z</dc:date>
    </item>
    <item>
      <title>Re: Match-Merge Data Sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Match-Merge-Data-Sets/m-p/703972#M215765</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/344636"&gt;@bhufman&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;YRDIF is not a statement. It is a function. Proper terminology matters in order to communicate effectively.&lt;/P&gt;
&lt;P&gt;Also, random uppercase and lowercase letters throughout the code makes it very hard to read. Same for no indentation and no alignment.&lt;/P&gt;
&lt;P&gt;Choose a format you like and stick to it. This will save you invaluable time. For example, language in lower case and data/user words in uppercase, like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   merge HYPTABS.DEMOG_1   (in= INDEMOG      drop= ETHRACECD          )
         HYPTABS.CONTACT_1 (in= INCONTACT    keep= SSN STATECD        )
         WORK.LASTVITALS   (in= INLASTVITALS drop= HTIN               )
         HYPTABS.NDI_1     (in= INNDI        drop= DEATHDT ICD10 CODCD) ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 06 Dec 2020 21:31:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Match-Merge-Data-Sets/m-p/703972#M215765</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-12-06T21:31:30Z</dc:date>
    </item>
    <item>
      <title>Re: Match-Merge Data Sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Match-Merge-Data-Sets/m-p/703982#M215769</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;UT_RECORDS dataset has 7 observations which have ID with 8 digits. The ID should have typically 9 digits as it is a SSN. Here the first digit of 0 needs to be added to make it work.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;This is the reason why&amp;nbsp;&lt;SPAN&gt;36-78-8134 in HypTabs.CONTACT and HypTabs.DEMOG didn't merge with 036-78-8134 in HypTabs.VITALS.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;You need to add the following when you create your CONTACT_UT and DEMOG_UT datasets which you created before:&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;IDChar = PUT(ID, 9.);&lt;BR /&gt;SSN = CATX("-", SUBSTR(IDChar, 1, 3), SUBSTR(IDChar, 4, 2), SUBSTR(IDChar, 6, 4));&lt;/P&gt;&lt;P&gt;IF ID &amp;lt; 100000000 THEN SSN = "0" || SSN;&lt;BR /&gt;&lt;BR /&gt;This ensures that if the ID has 8 digits, then a 0 is added as a prefix to the SSN.&lt;BR /&gt;&lt;BR /&gt;Once you make this change and generate the updated CONTACT and DEMOG datasets, you should get 573 observations.&lt;BR /&gt;&lt;BR /&gt;Please let me know if this doesn't work.&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Adhuna Mukhopadhyay&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 06 Dec 2020 22:11:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Match-Merge-Data-Sets/m-p/703982#M215769</guid>
      <dc:creator>adhunamukherjee</dc:creator>
      <dc:date>2020-12-06T22:11:11Z</dc:date>
    </item>
    <item>
      <title>Re: Match-Merge Data Sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Match-Merge-Data-Sets/m-p/703997#M215770</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/349689"&gt;@adhunamukherjee&lt;/a&gt;&amp;nbsp;With that kind of data, it's probably easier to merge numeric values.&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;if ID = input(compress(CHAR,,'dk'),10.);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 06 Dec 2020 23:17:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Match-Merge-Data-Sets/m-p/703997#M215770</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-12-06T23:17:55Z</dc:date>
    </item>
    <item>
      <title>Re: Match-Merge Data Sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Match-Merge-Data-Sets/m-p/704004#M215775</link>
      <description>&lt;P&gt;Thank you so much! This worked!&lt;/P&gt;</description>
      <pubDate>Mon, 07 Dec 2020 00:36:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Match-Merge-Data-Sets/m-p/704004#M215775</guid>
      <dc:creator>mdakkak</dc:creator>
      <dc:date>2020-12-07T00:36:16Z</dc:date>
    </item>
  </channel>
</rss>

