<?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: While merging two data sets by 2 common variables (subject_id in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/While-merging-two-data-sets-by-2-common-variables-subject-id-amp/m-p/848648#M37074</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/436120"&gt;@Rahim_221&lt;/a&gt;&amp;nbsp;I don't see how the data you showed in the initial question could possibly be a three-component date. You show it as a single variable, and the values only display month and year:&lt;/P&gt;
&lt;P&gt;First data set is as follows, (data1)&lt;/P&gt;
&lt;P&gt;Subject_id. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Measuredate&lt;/P&gt;
&lt;P&gt;ABC0001 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;8/2017&lt;/P&gt;
&lt;P&gt;ABC0002 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 10/2020&lt;/P&gt;
&lt;P&gt;ABC0005 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;9/2017&lt;/P&gt;
&lt;P&gt;The only way that those values could contain a day portion is if they were numeric SAS dates being displayed with a format like&amp;nbsp;&lt;STRONG&gt;mmyys10.&lt;/STRONG&gt;&amp;nbsp;For the other data set, you say &lt;STRONG&gt;Measuredate&lt;/STRONG&gt; contains only month and year. For that to be true, it would have to be a character (text) value. And if both of those things are true, you can't perform a SAS DATA step merge based on variables of different types.&amp;nbsp; So it would be useful to provide code that will re-recreate the two data sets to help us better understand the issues you are experiencing.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could try using the &lt;STRONG&gt;data2datastep&lt;/STRONG&gt; macro to produce the code required to reproduce your data. For example, this SAS program grabs the source code for the&amp;nbsp;&lt;STRONG&gt;data2datastep&amp;nbsp;&lt;/STRONG&gt;macro from the internet and compiles the macro for you. Then, a macro call reads the &lt;STRONG&gt;cars&lt;/STRONG&gt; dataset from the &lt;STRONG&gt;sashelp&lt;/STRONG&gt; library and generates a program that will re-create 10 observations of the data in the &lt;STRONG&gt;work&lt;/STRONG&gt; library. The program is saved to a file named&amp;nbsp;&lt;STRONG&gt;make_cars_data.sas &lt;/STRONG&gt;and in home directory (&lt;STRONG&gt;~/&lt;/STRONG&gt;&lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Get and compile the macro code from GitHub */
filename getmacro url "https://raw.githubusercontent.com/SASJedi/sas-macros/master/data2datastep.sas";
%include getmacro;
filename getmacro clear;

/* Call the macro to do the work */
%DATA2DATASTEP(cars,sashelp,work,~/make_cars_data.sas,10)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you just leave the last parameter blank, the whole dataset will be re-created. After running that program, the&amp;nbsp;&lt;STRONG&gt;make_cars_data.s&lt;/STRONG&gt;as looks like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.CARS(label='2004 Car Data');
  infile datalines dsd truncover;
  input Make:$13. Model:$40. Type:$8. Origin:$6. DriveTrain:$5. MSRP:DOLLAR8. Invoice:DOLLAR8. EngineSize:32. Cylinders:32. Horsepower:32. MPG_City:32. MPG_Highway:32. Weight:32. Wheelbase:32. Length:32.;
  format MSRP DOLLAR8. Invoice DOLLAR8.;
  label EngineSize="Engine Size (L)" MPG_City="MPG (City)" MPG_Highway="MPG (Highway)" Weight="Weight (LBS)" Wheelbase="Wheelbase (IN)" Length="Length (IN)";
datalines4;
Acura,MDX,SUV,Asia,All,"$36,945","$33,337",3.5,6,265,17,23,4451,106,189
Acura,RSX Type S 2dr,Sedan,Asia,Front,"$23,820","$21,761",2,4,200,24,31,2778,101,172
Acura,TSX 4dr,Sedan,Asia,Front,"$26,990","$24,647",2.4,4,200,22,29,3230,105,183
Acura,TL 4dr,Sedan,Asia,Front,"$33,195","$30,299",3.2,6,270,20,28,3575,108,186
Acura,3.5 RL 4dr,Sedan,Asia,Front,"$43,755","$39,014",3.5,6,225,18,24,3880,115,197
;;;;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you do that for both of your data sets and then share the resulting code to reproduce them here, we can help resolve the problem more quickly.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All the best,&lt;/P&gt;
&lt;P&gt;Mark&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 08 Dec 2022 20:03:45 GMT</pubDate>
    <dc:creator>SASJedi</dc:creator>
    <dc:date>2022-12-08T20:03:45Z</dc:date>
    <item>
      <title>While merging two data sets by 2 common variables (subject_id &amp; date), some values are missing.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/While-merging-two-data-sets-by-2-common-variables-subject-id-amp/m-p/848448#M37027</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I have to merge two data sets by subject_id and measure date.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;First data set is as follows, (data1)&lt;/P&gt;&lt;P&gt;Subject_id. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Measure-date&lt;/P&gt;&lt;P&gt;ABC0001 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;8/2017&lt;/P&gt;&lt;P&gt;ABC0002 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 10/2020&lt;/P&gt;&lt;P&gt;ABC0005 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;9/2017&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Second data set is as follows; (data2)&lt;/P&gt;&lt;P&gt;Subject_id &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Measuredate &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;height &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;weight &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; record_number&lt;/P&gt;&lt;P&gt;ABC0001 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 5/2012 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 176 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;56 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;500&lt;/P&gt;&lt;P&gt;ABC0001 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 6/2016 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 180 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;70 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 500&lt;/P&gt;&lt;P&gt;ABC0001 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 8/2017 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 182 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;99 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;500&lt;/P&gt;&lt;P&gt;ABC0002 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 10/2020 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;160 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 55 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;510&lt;/P&gt;&lt;P&gt;ABC0002 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;11/2021 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;170 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;66 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;510&lt;/P&gt;&lt;P&gt;ABC0005 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 9/2017 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;190 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;80 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 502&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Desired data is as follows; (data want)&lt;/P&gt;&lt;P&gt;Subject_id &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;measure date &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;height &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; weight &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;record_number&lt;/P&gt;&lt;P&gt;ABC0001 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 8/2017 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 182 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;99 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;500&lt;/P&gt;&lt;P&gt;ABC0002 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 10/2020 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;160 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;55 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;510&lt;/P&gt;&lt;P&gt;ABC0005 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;9/2017 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;190 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;80 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;502&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Problem is as follows:&lt;/P&gt;&lt;P&gt;The data that I get:&lt;/P&gt;&lt;P&gt;Subject_id &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;measure date &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;height &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; weight &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;record_number&lt;/P&gt;&lt;P&gt;ABC0001 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 8/2017 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 182 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;99 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;500&lt;/P&gt;&lt;P&gt;ABC0002 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 10/2020 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;/P&gt;&lt;P&gt;ABC0005 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;9/2017 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; . &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The dataset I am working on is ACTUALLY thousands of observations. When I merge the data sets, I get some observations merged as desired, while the majority of the other observations are appearing as missing data. I am not sure what the problem is.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code I am using is:&lt;/P&gt;&lt;P&gt;Proc sort data=data1; by subject_id &amp;nbsp;measuredate;run;&lt;/P&gt;&lt;P&gt;proc sort data=data2; by &amp;nbsp;subject_id &amp;nbsp; measure date; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;merge data1 (in=a) &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;data2 (in=b); by&amp;nbsp;subject_id &amp;nbsp;measuredate; if b; run;\&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;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Dec 2022 01:44:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/While-merging-two-data-sets-by-2-common-variables-subject-id-amp/m-p/848448#M37027</guid>
      <dc:creator>Rahim_221</dc:creator>
      <dc:date>2022-12-08T01:44:09Z</dc:date>
    </item>
    <item>
      <title>Re: While merging two data sets by 2 common variables (subject_id &amp; date), some values are missi</title>
      <link>https://communities.sas.com/t5/New-SAS-User/While-merging-two-data-sets-by-2-common-variables-subject-id-amp/m-p/848450#M37028</link>
      <description>&lt;P&gt;I strongly suspect that "measure date" is your problem. It appears to be a character variable and it looks like it is affected by leading blanks. To confirm what your variable types are run this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc contents data = data1;
run;

proc contents data = data2;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If&amp;nbsp;measure date is character, then it would be a very good idea to convert it to a numeric SAS date. That might require adding a day to the month and year you currently have like the first or last day of the month.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Dec 2022 02:32:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/While-merging-two-data-sets-by-2-common-variables-subject-id-amp/m-p/848450#M37028</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2022-12-08T02:32:01Z</dc:date>
    </item>
    <item>
      <title>Re: While merging two data sets by 2 common variables (subject_id</title>
      <link>https://communities.sas.com/t5/New-SAS-User/While-merging-two-data-sets-by-2-common-variables-subject-id-amp/m-p/848459#M37029</link>
      <description>Hello,&lt;BR /&gt;Thank you for attempting to answer my question. I would like to provide some additional discoveries on my end.&lt;BR /&gt;The measuredate column in dataset 1 is made of day, month, and year, while the same variable in dataset 2 is only made of a month and year. Therefore, in dataset 1, I created a new measuredate column (from the original measuredate col) that consists only of month and year and I did that to match the variable measuredate in dataset 2. Even tho the newly created col of only month and yr is visible as (09/2017, for example) it is still actually a day, month, and year. I used the below code to create a to component date from the three components date.&lt;BR /&gt;&lt;BR /&gt;So, what I have now is a key merging column in dataset 2 that consist of a two component date, while its equivalent in dataset 1 is a three component date that appears as a two component date.&lt;BR /&gt;I hope I was able to properly represent this to you as I believe the problem lies there.&lt;BR /&gt;</description>
      <pubDate>Thu, 08 Dec 2022 03:46:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/While-merging-two-data-sets-by-2-common-variables-subject-id-amp/m-p/848459#M37029</guid>
      <dc:creator>Rahim_221</dc:creator>
      <dc:date>2022-12-08T03:46:41Z</dc:date>
    </item>
    <item>
      <title>Re: While merging two data sets by 2 common variables (subject_id</title>
      <link>https://communities.sas.com/t5/New-SAS-User/While-merging-two-data-sets-by-2-common-variables-subject-id-amp/m-p/848648#M37074</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/436120"&gt;@Rahim_221&lt;/a&gt;&amp;nbsp;I don't see how the data you showed in the initial question could possibly be a three-component date. You show it as a single variable, and the values only display month and year:&lt;/P&gt;
&lt;P&gt;First data set is as follows, (data1)&lt;/P&gt;
&lt;P&gt;Subject_id. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Measuredate&lt;/P&gt;
&lt;P&gt;ABC0001 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;8/2017&lt;/P&gt;
&lt;P&gt;ABC0002 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 10/2020&lt;/P&gt;
&lt;P&gt;ABC0005 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;9/2017&lt;/P&gt;
&lt;P&gt;The only way that those values could contain a day portion is if they were numeric SAS dates being displayed with a format like&amp;nbsp;&lt;STRONG&gt;mmyys10.&lt;/STRONG&gt;&amp;nbsp;For the other data set, you say &lt;STRONG&gt;Measuredate&lt;/STRONG&gt; contains only month and year. For that to be true, it would have to be a character (text) value. And if both of those things are true, you can't perform a SAS DATA step merge based on variables of different types.&amp;nbsp; So it would be useful to provide code that will re-recreate the two data sets to help us better understand the issues you are experiencing.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could try using the &lt;STRONG&gt;data2datastep&lt;/STRONG&gt; macro to produce the code required to reproduce your data. For example, this SAS program grabs the source code for the&amp;nbsp;&lt;STRONG&gt;data2datastep&amp;nbsp;&lt;/STRONG&gt;macro from the internet and compiles the macro for you. Then, a macro call reads the &lt;STRONG&gt;cars&lt;/STRONG&gt; dataset from the &lt;STRONG&gt;sashelp&lt;/STRONG&gt; library and generates a program that will re-create 10 observations of the data in the &lt;STRONG&gt;work&lt;/STRONG&gt; library. The program is saved to a file named&amp;nbsp;&lt;STRONG&gt;make_cars_data.sas &lt;/STRONG&gt;and in home directory (&lt;STRONG&gt;~/&lt;/STRONG&gt;&lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Get and compile the macro code from GitHub */
filename getmacro url "https://raw.githubusercontent.com/SASJedi/sas-macros/master/data2datastep.sas";
%include getmacro;
filename getmacro clear;

/* Call the macro to do the work */
%DATA2DATASTEP(cars,sashelp,work,~/make_cars_data.sas,10)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you just leave the last parameter blank, the whole dataset will be re-created. After running that program, the&amp;nbsp;&lt;STRONG&gt;make_cars_data.s&lt;/STRONG&gt;as looks like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.CARS(label='2004 Car Data');
  infile datalines dsd truncover;
  input Make:$13. Model:$40. Type:$8. Origin:$6. DriveTrain:$5. MSRP:DOLLAR8. Invoice:DOLLAR8. EngineSize:32. Cylinders:32. Horsepower:32. MPG_City:32. MPG_Highway:32. Weight:32. Wheelbase:32. Length:32.;
  format MSRP DOLLAR8. Invoice DOLLAR8.;
  label EngineSize="Engine Size (L)" MPG_City="MPG (City)" MPG_Highway="MPG (Highway)" Weight="Weight (LBS)" Wheelbase="Wheelbase (IN)" Length="Length (IN)";
datalines4;
Acura,MDX,SUV,Asia,All,"$36,945","$33,337",3.5,6,265,17,23,4451,106,189
Acura,RSX Type S 2dr,Sedan,Asia,Front,"$23,820","$21,761",2,4,200,24,31,2778,101,172
Acura,TSX 4dr,Sedan,Asia,Front,"$26,990","$24,647",2.4,4,200,22,29,3230,105,183
Acura,TL 4dr,Sedan,Asia,Front,"$33,195","$30,299",3.2,6,270,20,28,3575,108,186
Acura,3.5 RL 4dr,Sedan,Asia,Front,"$43,755","$39,014",3.5,6,225,18,24,3880,115,197
;;;;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you do that for both of your data sets and then share the resulting code to reproduce them here, we can help resolve the problem more quickly.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All the best,&lt;/P&gt;
&lt;P&gt;Mark&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Dec 2022 20:03:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/While-merging-two-data-sets-by-2-common-variables-subject-id-amp/m-p/848648#M37074</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2022-12-08T20:03:45Z</dc:date>
    </item>
    <item>
      <title>Re: While merging two data sets by 2 common variables (subject_id</title>
      <link>https://communities.sas.com/t5/New-SAS-User/While-merging-two-data-sets-by-2-common-variables-subject-id-amp/m-p/848652#M37075</link>
      <description>Thank you Mark for your reply. The variable measuredate in my data set is&lt;BR /&gt;actually a variable that I created for both my data sets to be able to&lt;BR /&gt;merge. It is in a format mmyys10.&lt;BR /&gt;&lt;BR /&gt;The reason I did that, is because my data1 contains a date variable that&lt;BR /&gt;has only month and year, while date set 2 has a date variable in format&lt;BR /&gt;mmddyy10.&lt;BR /&gt;So I can’t merge two data sets by date variable if it’s not in identical&lt;BR /&gt;format in both data set, that’s why I created measuredate in mmyys10.&lt;BR /&gt;&lt;BR /&gt;I now know the reason why the merge is incorrect, because the measuredate&lt;BR /&gt;variable is formated but doesn’t mean the day is not there anymore. It&lt;BR /&gt;means that it is only showing month and year but day is still there not&lt;BR /&gt;showing. So when I attempted to merge, the day is not matching in both data&lt;BR /&gt;sets.&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;</description>
      <pubDate>Thu, 08 Dec 2022 20:12:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/While-merging-two-data-sets-by-2-common-variables-subject-id-amp/m-p/848652#M37075</guid>
      <dc:creator>Rahim_221</dc:creator>
      <dc:date>2022-12-08T20:12:41Z</dc:date>
    </item>
    <item>
      <title>Re: While merging two data sets by 2 common variables (subject_id &amp; date), some values are missi</title>
      <link>https://communities.sas.com/t5/New-SAS-User/While-merging-two-data-sets-by-2-common-variables-subject-id-amp/m-p/848654#M37076</link>
      <description>&lt;P&gt;It is only going to work if the variables are storing the same type of information.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If they are numeric variables with date values then make sure they are aligned to the same date of the month.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;measure_date = intnx('month',measure_date,0);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If they are character strings make sure they are consistently formatted.&amp;nbsp; Do the months have leading zeros or not?&amp;nbsp; Do the values have leading spaces or not?&amp;nbsp; It would probably be better to convert them into date values instead of leaving them as character strings.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;measure_date_number = input(cats('1/',measure_date),ddmmyy10.);
format measure_date_number yymms7.;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you leave them as charcter strings then standardize the style used.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;measure_date = put(input(cats('1/',measure_date),ddmmyy10.),yymms7.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that it is best to store dates as character strings in YMD order so that when sorted they will appear in chronological order.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Dec 2022 20:19:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/While-merging-two-data-sets-by-2-common-variables-subject-id-amp/m-p/848654#M37076</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-12-08T20:19:18Z</dc:date>
    </item>
    <item>
      <title>Re: While merging two data sets by 2 common variables (subject_id</title>
      <link>https://communities.sas.com/t5/New-SAS-User/While-merging-two-data-sets-by-2-common-variables-subject-id-amp/m-p/848661#M37077</link>
      <description>&lt;P&gt;If both variables are actually SAS date values, align them to the first day of the month by using the INTNX function with the "b" modifier.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;measure_date = intnx('month',measure_date,0,'b');&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 08 Dec 2022 21:37:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/While-merging-two-data-sets-by-2-common-variables-subject-id-amp/m-p/848661#M37077</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-12-08T21:37:47Z</dc:date>
    </item>
    <item>
      <title>Re: While merging two data sets by 2 common variables (subject_id</title>
      <link>https://communities.sas.com/t5/New-SAS-User/While-merging-two-data-sets-by-2-common-variables-subject-id-amp/m-p/848664#M37078</link>
      <description>Thank you</description>
      <pubDate>Thu, 08 Dec 2022 22:16:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/While-merging-two-data-sets-by-2-common-variables-subject-id-amp/m-p/848664#M37078</guid>
      <dc:creator>Rahim_221</dc:creator>
      <dc:date>2022-12-08T22:16:44Z</dc:date>
    </item>
    <item>
      <title>Re: While merging two data sets by 2 common variables (subject_id &amp; date), some values are missi</title>
      <link>https://communities.sas.com/t5/New-SAS-User/While-merging-two-data-sets-by-2-common-variables-subject-id-amp/m-p/848665#M37079</link>
      <description>&lt;P&gt;You apparently want one record per id, containing measure_date from DATA1 (which only has 1 obs per id), and all other variables from the most recent obs in DATA2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If so, assuming data1 is sorted by ID, and data2 is sorted by ID/measure_date, then:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  merge data1 data2 (drop=measure_date);
  by id;
  if last.id;
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;</description>
      <pubDate>Thu, 08 Dec 2022 22:29:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/While-merging-two-data-sets-by-2-common-variables-subject-id-amp/m-p/848665#M37079</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-12-08T22:29:07Z</dc:date>
    </item>
  </channel>
</rss>

