<?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: Problem with merging two tables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-merging-two-tables/m-p/425729#M104877</link>
    <description>&lt;P&gt;Your import code is not working correctly.&amp;nbsp; After some fiddling with it I got to this, you can take it further from here and process out to what you want:&lt;/P&gt;
&lt;PRE&gt;data jo_medailles;
  infile "s:temp/r.txt" firstobs=10 dlm='*';
  length lne year country country_long $200;
  retain lne;
  input;
  if substr(strip(_infile_),1,5)="Disci" then lne=_infile_;
  else if substr(_infile_,1,5)="-----" then delete;
  else do;
    year=strip(substr(_infile_,1,4));
    country=strip(substr(_infile_,6,11));
    country_long=strip(substr(_infile_,17,30));
    output;
  end;
run;&lt;/PRE&gt;
&lt;P&gt;Also, that file pretty bad for importing, is there not a way you could get a nice CSV or XML version of the data, would make your life easier than some report file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 08 Jan 2018 12:06:59 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2018-01-08T12:06:59Z</dc:date>
    <item>
      <title>Problem with merging two tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-merging-two-tables/m-p/425719#M104872</link>
      <description>&lt;P&gt;Hi, I would like to merge two tables (1-n) but I can't, I have this kind of result :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;IMG src="https://img15.hostingpics.net/pics/581324Mergingproblem.jpg" border="0" /&gt;&lt;/P&gt;&lt;P&gt;Here is my code :&lt;/P&gt;&lt;PRE&gt;DATA tabTemp;
SET malib.JO_organisation_annee (DROP=date_debut--nb_athletes_f);
RUN;

PROC SORT DATA=tabTemp OUT=work.Jo_organisation_m;
BY annee;
RUN;

PROC SORT DATA=malib.Jo_medailles OUT=work.Jo_medailles_m;
BY annee;
RUN;

DATA TEMP;
MERGE Jo_organisation_m (IN=A) Jo_medailles_m (IN=B);
By annee;
RUN;&lt;/PRE&gt;&lt;P&gt;Thanks for your help.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jan 2018 11:20:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-merging-two-tables/m-p/425719#M104872</guid>
      <dc:creator>Num19</dc:creator>
      <dc:date>2018-01-08T11:20:59Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with merging two tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-merging-two-tables/m-p/425720#M104873</link>
      <description>&lt;P&gt;Post some sample data along with your problem we can use.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It makes it much easier to help &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jan 2018 11:22:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-merging-two-tables/m-p/425720#M104873</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2018-01-08T11:22:47Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with merging two tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-merging-two-tables/m-p/425722#M104874</link>
      <description>&lt;P&gt;Sorry, there is two tables, the first is JO_organisation_annee, the second is created by this code :&lt;/P&gt;&lt;PRE&gt;DATA malib.Jo_medailles;
INFILE "C:\Users\Desktop\Projet\Résultats Jeux Olympiques.txt" FIRSTOBS=10;
RETAIN code_discipline discipline;
INPUT test :$32. @;
	  IF test="Discipline" THEN INPUT test $ code_discipline $ discipline :$CHAR32.;
	  	  ELSE IF test in(1924:2014) THEN DO;
			INPUT annee $ 1-12 code_pays $ 14-16 pays $ 25-48 type_medaille $ 49-63 nb_medailles 64;
			OUTPUT;
	  END; 
DROP test;
RUN;&lt;/PRE&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jan 2018 11:37:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-merging-two-tables/m-p/425722#M104874</guid>
      <dc:creator>Num19</dc:creator>
      <dc:date>2018-01-08T11:37:20Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with merging two tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-merging-two-tables/m-p/425723#M104875</link>
      <description>&lt;P&gt;Posting pictures doesn't really help much.&amp;nbsp; From that picture however, it can clearly be seen that in the first table the variable annee contains a number for instance '&amp;nbsp; &amp;nbsp;1924' - possibly meaning a year.&amp;nbsp; In the second table annee seems to contain text data 'AUS' for example.&amp;nbsp; As these clearly are not the same, then the data from the second table appears under the first, and no merge occurs.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Without some further information I can't say anything else other than avoid coding all in uppercase or mixed case, it makes reading the code so much harder:&lt;/P&gt;
&lt;PRE&gt;data tabtemp;
  set malib.jo_organisation_annee (drop=date_debut--nb_athletes_f);
run;&lt;/PRE&gt;</description>
      <pubDate>Mon, 08 Jan 2018 11:40:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-merging-two-tables/m-p/425723#M104875</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-01-08T11:40:48Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with merging two tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-merging-two-tables/m-p/425724#M104876</link>
      <description>&lt;P&gt;Annee are both numeric values in those two tables.&lt;/P&gt;&lt;P&gt;How can I add a table (attachments) ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jan 2018 11:45:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-merging-two-tables/m-p/425724#M104876</guid>
      <dc:creator>Num19</dc:creator>
      <dc:date>2018-01-08T11:45:15Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with merging two tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-merging-two-tables/m-p/425729#M104877</link>
      <description>&lt;P&gt;Your import code is not working correctly.&amp;nbsp; After some fiddling with it I got to this, you can take it further from here and process out to what you want:&lt;/P&gt;
&lt;PRE&gt;data jo_medailles;
  infile "s:temp/r.txt" firstobs=10 dlm='*';
  length lne year country country_long $200;
  retain lne;
  input;
  if substr(strip(_infile_),1,5)="Disci" then lne=_infile_;
  else if substr(_infile_,1,5)="-----" then delete;
  else do;
    year=strip(substr(_infile_,1,4));
    country=strip(substr(_infile_,6,11));
    country_long=strip(substr(_infile_,17,30));
    output;
  end;
run;&lt;/PRE&gt;
&lt;P&gt;Also, that file pretty bad for importing, is there not a way you could get a nice CSV or XML version of the data, would make your life easier than some report file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jan 2018 12:06:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-merging-two-tables/m-p/425729#M104877</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-01-08T12:06:59Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with merging two tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-merging-two-tables/m-p/425731#M104878</link>
      <description>&lt;P&gt;Post example data in data steps. Use the macro from&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; to convert your dataset(s) to data step(s), and then post the resulting code in a code window as described in &lt;A href="https://communities.sas.com/t5/help/faqpage/faq-category-id/posting?nobounce" target="_blank"&gt;https://communities.sas.com/t5/help/faqpage/faq-category-id/posting?nobounce&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;Use the same method to post your code, as the code subwindow will preserve formatting (indentation) and not change certain specific characters/character sequences.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jan 2018 12:10:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-merging-two-tables/m-p/425731#M104878</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-01-08T12:10:38Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with merging two tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-merging-two-tables/m-p/425733#M104879</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/185408"&gt;@Num19&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Annee are both numeric values in those two tables.&lt;/P&gt;
&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Can't be. 'AUS' is not a numeric value, so annee must be of type character. Or you have a numeric value behind 'AUS' that is displayed as 'AUS' because of a format. But then it's clearly not a year.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jan 2018 12:12:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-merging-two-tables/m-p/425733#M104879</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-01-08T12:12:30Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with merging two tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-merging-two-tables/m-p/425735#M104880</link>
      <description>&lt;P&gt;Seeing this code piece:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;INPUT annee $ 1-12&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;it becomes clear that annee is NOT numeric.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jan 2018 12:14:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-merging-two-tables/m-p/425735#M104880</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-01-08T12:14:14Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with merging two tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-merging-two-tables/m-p/425744#M104881</link>
      <description>&lt;P&gt;I don't know where is the Autoexec file.&lt;/P&gt;&lt;P&gt;Sorry but I meant Alphanumeric.&lt;/P&gt;&lt;P&gt;Here is the good pic :&lt;/P&gt;&lt;P&gt;&lt;IMG src="https://img15.hostingpics.net/pics/632750IMG1885.jpg" border="0" /&gt;&lt;/P&gt;&lt;P&gt;I'm sorry but I can't use an other way to import data I have to follow some instructions.&lt;/P&gt;&lt;P&gt;Via that code :&lt;/P&gt;&lt;PRE&gt;DATA import;
INFILE CARDS4 DLM=";";
RETAIN nom; 
INPUT test $ @; 
	  IF test ="NOM" THEN INPUT nom $;
	  ELSE IF test="PRENOM" THEN DO; 
			INPUT prenom $;
			OUTPUT;
	  END;
DROP test; 
CARDS4; 
NOM;DUPONT
PRENOM;PIERRE
PRENOM;SOPHIE
NOM;MARTIN
PRENOM;THOMAS
;;;; 
RUN;&lt;/PRE&gt;&lt;P&gt;I had to build one of my own to import data from (Inspiring of the previous code) :&lt;/P&gt;&lt;PRE&gt;"C:\Users\Desktop\Projet\Résultats Jeux Olympiques.txt"&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;And that's what I did :&lt;/P&gt;&lt;PRE&gt;DATA malib.Jo_medailles;
INFILE "C:\Users\Réda\Desktop\Organisation\Master\Maths et Finance\S1\SAS\Tables\Résultats Jeux Olympiques.txt" FIRSTOBS=10;
RETAIN code_discipline discipline;
INPUT test :$32. @;
	  IF test="Discipline" THEN INPUT test $ code_discipline $ discipline :$CHAR32.;
	  	  ELSE IF test in(1924:2014) THEN DO;
			INPUT annee $ 1-12 code_pays $ 14-16 pays $ 25-48 type_medaille $ 49-63 nb_medailles 64;
			OUTPUT;
	  END; 
DROP test;
RUN;&lt;/PRE&gt;</description>
      <pubDate>Mon, 08 Jan 2018 13:03:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-merging-two-tables/m-p/425744#M104881</guid>
      <dc:creator>Num19</dc:creator>
      <dc:date>2018-01-08T13:03:56Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with merging two tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-merging-two-tables/m-p/425749#M104882</link>
      <description>&lt;P&gt;So you have differently formatted values (right- or left-aligned) in annee. Before merging, you need to standardize your data; since all the values are indeed numeric, I'd convert to a numeric variable in both datasets, using this code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data jo_organisation_m;
set malib.jo_organisation_annee (drop=date_debut--nb_athletes_f);
annee_num = input(annee,best.);
drop annee;
run;

proc sort data=jo_organisation_m;
by annee_num;
run;

data jo_medailles_m;
set malib.jo_medailles;
annee_num = input(annee,best.);
drop annee;
run;

proc sort data=jo_medailles_m;
by annee_num;
run;

data temp;
merge
  jo_organisation_m (in=A)
  jo_medailles_m (in=B)
;
by annee_num;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 08 Jan 2018 13:02:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-merging-two-tables/m-p/425749#M104882</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-01-08T13:02:37Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with merging two tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-merging-two-tables/m-p/425756#M104884</link>
      <description>&lt;P&gt;Out of the topic but why do I have in "Discipline" the data Ski instead of "Ski de fond" or "Ski acrobatique" like in the text file ?&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jan 2018 13:19:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-merging-two-tables/m-p/425756#M104884</guid>
      <dc:creator>Num19</dc:creator>
      <dc:date>2018-01-08T13:19:13Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with merging two tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-merging-two-tables/m-p/425768#M104887</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/185408"&gt;@Num19&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Out of the topic but why do I have in "Discipline" the data Ski instead of "Ski de fond" or "Ski acrobatique" like in the text file ?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Because you use simple list input in the respective input statement, and that means that a blank will be used as a separator.&lt;/P&gt;
&lt;P&gt;That particular piece of code would better look like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data malib.jo_medailles;
infile
  "C:\Users\Réda\Desktop\Organisation\Master\Maths et Finance\S1\SAS\Tables\Résultats Jeux Olympiques.txt"
  firstobs=10
  truncover
;
retain code_discipline discipline;
input test :$10. @;
if test = "Discipline"
then input test $ code_discipline $ discipline $char32.;
else if test ne '----------'
then do;
  input
    annee $ 1-12
    code_pays $ 14-16
    pays $ 25-48
    type_medaille $ 49-63
    nb_medailles 64
  ;
  output;
end; 
drop test;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 08 Jan 2018 14:23:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-merging-two-tables/m-p/425768#M104887</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-01-08T14:23:26Z</dc:date>
    </item>
  </channel>
</rss>

