<?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 Error By variables are not properly sorted. But I have already made proc sort step in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Error-By-variables-are-not-properly-sorted-But-I-have-already/m-p/703570#M79925</link>
    <description>&lt;P&gt;Hi I get the error message "Error By variables are not properly sorted. but I have a proc sort step for each dataset prior to the merge statement.&lt;/P&gt;&lt;P&gt;code looks like this: (sadly can copy-paste as data is on a secure server without browser access.)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sort data="....(pathway)....." out=Population;&lt;/P&gt;&lt;P&gt;by pnr;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;Proc print data=Population;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;proc sort data="....(pathway)....." out=DTSPNR;&lt;/P&gt;&lt;P&gt;by pnr;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;Proc print data=DTSPNR;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data DTS_Merged_Population;&lt;/P&gt;&lt;P&gt;merge "...(pathway)..." "...(pathway)...";&lt;/P&gt;&lt;P&gt;by pnr;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;what am I doing wrong?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 04 Dec 2020 09:17:59 GMT</pubDate>
    <dc:creator>Jannie_D</dc:creator>
    <dc:date>2020-12-04T09:17:59Z</dc:date>
    <item>
      <title>Error By variables are not properly sorted. But I have already made proc sort step</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Error-By-variables-are-not-properly-sorted-But-I-have-already/m-p/703570#M79925</link>
      <description>&lt;P&gt;Hi I get the error message "Error By variables are not properly sorted. but I have a proc sort step for each dataset prior to the merge statement.&lt;/P&gt;&lt;P&gt;code looks like this: (sadly can copy-paste as data is on a secure server without browser access.)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sort data="....(pathway)....." out=Population;&lt;/P&gt;&lt;P&gt;by pnr;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;Proc print data=Population;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;proc sort data="....(pathway)....." out=DTSPNR;&lt;/P&gt;&lt;P&gt;by pnr;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;Proc print data=DTSPNR;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data DTS_Merged_Population;&lt;/P&gt;&lt;P&gt;merge "...(pathway)..." "...(pathway)...";&lt;/P&gt;&lt;P&gt;by pnr;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;what am I doing wrong?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Dec 2020 09:17:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Error-By-variables-are-not-properly-sorted-But-I-have-already/m-p/703570#M79925</guid>
      <dc:creator>Jannie_D</dc:creator>
      <dc:date>2020-12-04T09:17:59Z</dc:date>
    </item>
    <item>
      <title>Re: Error By variables are not properly sorted. But I have already made proc sort step</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Error-By-variables-are-not-properly-sorted-But-I-have-already/m-p/703572#M79926</link>
      <description>&lt;P&gt;Post your log please&lt;/P&gt;</description>
      <pubDate>Fri, 04 Dec 2020 09:22:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Error-By-variables-are-not-properly-sorted-But-I-have-already/m-p/703572#M79926</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-12-04T09:22:42Z</dc:date>
    </item>
    <item>
      <title>Re: Error By variables are not properly sorted. But I have already made proc sort step</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Error-By-variables-are-not-properly-sorted-But-I-have-already/m-p/703574#M79927</link>
      <description>I sadly ca not post it as I can't copy paste it, because of safety restrictions.&lt;BR /&gt;&lt;BR /&gt;but it has notes prior to the error saying&lt;BR /&gt;note: format $DTS_JN was not found or could not be loaded&lt;BR /&gt;for around 30 variables.&lt;BR /&gt;so I guess that is the problem. but how do I solve that?&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 04 Dec 2020 09:41:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Error-By-variables-are-not-properly-sorted-But-I-have-already/m-p/703574#M79927</guid>
      <dc:creator>Jannie_D</dc:creator>
      <dc:date>2020-12-04T09:41:19Z</dc:date>
    </item>
    <item>
      <title>Re: Error By variables are not properly sorted. But I have already made proc sort step</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Error-By-variables-are-not-properly-sorted-But-I-have-already/m-p/703575#M79928</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/359624"&gt;@Jannie_D&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi I get the error message "Error By variables are not properly sorted. but I have a proc sort step for each dataset prior to the merge statement.&lt;/P&gt;
&lt;P&gt;code looks like this: (sadly can copy-paste as data is on a secure server without browser access.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data="....(pathway)....." out=Population;&lt;/P&gt;
&lt;P&gt;by pnr;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;Proc print data=Population;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;proc sort data="....(pathway)....." out=DTSPNR;&lt;/P&gt;
&lt;P&gt;by pnr;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;Proc print data=DTSPNR;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data DTS_Merged_Population;&lt;/P&gt;
&lt;P&gt;merge &lt;STRONG&gt;&lt;FONT color="#FF6600"&gt;"...(pathway)..." "...(pathway)..."&lt;/FONT&gt;&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;by pnr;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;what am I doing wrong?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The problem is highlighted in &lt;FONT color="#FF6600"&gt;orange&lt;/FONT&gt;. In the merge-statement, you must use the sorted versions of your datasets.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Dec 2020 09:57:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Error-By-variables-are-not-properly-sorted-But-I-have-already/m-p/703575#M79928</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-12-04T09:57:11Z</dc:date>
    </item>
    <item>
      <title>Re: Error By variables are not properly sorted. But I have already made proc sort step</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Error-By-variables-are-not-properly-sorted-But-I-have-already/m-p/703576#M79929</link>
      <description>Thank you.&lt;BR /&gt;I will try to change that.&lt;BR /&gt;would a libref be sufficient or should I create a datastep first?&lt;BR /&gt;I'm a SAS beginner</description>
      <pubDate>Fri, 04 Dec 2020 10:21:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Error-By-variables-are-not-properly-sorted-But-I-have-already/m-p/703576#M79929</guid>
      <dc:creator>Jannie_D</dc:creator>
      <dc:date>2020-12-04T10:21:20Z</dc:date>
    </item>
    <item>
      <title>Re: Error By variables are not properly sorted. But I have already made proc sort step</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Error-By-variables-are-not-properly-sorted-But-I-have-already/m-p/703577#M79930</link>
      <description>&lt;P&gt;All you need at this point is to list the sorted datasets in the merge statement. Just keep in mind that any variables that each dataset has in common, the dataset listed 2nd will overwrite values in the 1st.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Dec 2020 10:29:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Error-By-variables-are-not-properly-sorted-But-I-have-already/m-p/703577#M79930</guid>
      <dc:creator>benjamin_2018</dc:creator>
      <dc:date>2020-12-04T10:29:53Z</dc:date>
    </item>
    <item>
      <title>Re: Error By variables are not properly sorted. But I have already made proc sort step</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Error-By-variables-are-not-properly-sorted-But-I-have-already/m-p/703583#M79931</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/359624"&gt;@Jannie_D&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One additional note to&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/238027"&gt;@benjamin_2018&lt;/a&gt;&amp;nbsp;comment,&lt;/P&gt;
&lt;P&gt;if you have many-to-many keys in merge it won't work the same way SQL's joins do.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15475"&gt;@andreas_lds&lt;/a&gt;&amp;nbsp;wrote can be simply done in the following way:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data="....(pathway)....." out=Population;
  by pnr;
run;

Proc print data=Population;
run;

proc sort data="....(pathway)....." out=DTSPNR;
  by pnr;
run;

Proc print data=DTSPNR;
run; 

Data DTS_Merged_Population;
  merge Population DTSPNR;
  by pnr;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Btw. if I were you I would change the&amp;nbsp;&lt;CODE class=" language-sas"&gt;"....(pathway)....."&lt;/CODE&gt; to libname statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All the best&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Dec 2020 11:04:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Error-By-variables-are-not-properly-sorted-But-I-have-already/m-p/703583#M79931</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-12-04T11:04:08Z</dc:date>
    </item>
    <item>
      <title>Re: Error By variables are not properly sorted. But I have already made proc sort step</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Error-By-variables-are-not-properly-sorted-But-I-have-already/m-p/703587#M79932</link>
      <description>&lt;P&gt;none of the solutions helped other ideas&amp;nbsp;&lt;/P&gt;&lt;P&gt;I now added af data step before the rest to avoid using a pathway in the merge step&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Dec 2020 11:33:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Error-By-variables-are-not-properly-sorted-But-I-have-already/m-p/703587#M79932</guid>
      <dc:creator>Jannie_D</dc:creator>
      <dc:date>2020-12-04T11:33:58Z</dc:date>
    </item>
    <item>
      <title>Re: Error By variables are not properly sorted. But I have already made proc sort step</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Error-By-variables-are-not-properly-sorted-But-I-have-already/m-p/703614#M79933</link>
      <description>&lt;P&gt;POST THE LOG.&lt;/P&gt;
&lt;P&gt;Edit out any confidential information (overwrite it with X's), but leave the horizontal structure and all messages intact.&lt;/P&gt;
&lt;P&gt;Post the complete log of all SORT and DATA steps, as you run them in one submit.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Without seeing the log, it's next to impossible to help someone who's new to the field and has problems describing what &lt;EM&gt;exactly&lt;/EM&gt; is done and what &lt;EM&gt;exactly&lt;/EM&gt; happens.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Dec 2020 13:23:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Error-By-variables-are-not-properly-sorted-But-I-have-already/m-p/703614#M79933</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-12-04T13:23:33Z</dc:date>
    </item>
    <item>
      <title>Re: Error By variables are not properly sorted. But I have already made proc sort step</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Error-By-variables-are-not-properly-sorted-But-I-have-already/m-p/703616#M79934</link>
      <description>As I wrote earlier because it is a secure drive with acces to a browser is it not possible to do a copy paste. And there a many lines in that log.</description>
      <pubDate>Fri, 04 Dec 2020 13:26:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Error-By-variables-are-not-properly-sorted-But-I-have-already/m-p/703616#M79934</guid>
      <dc:creator>Jannie_D</dc:creator>
      <dc:date>2020-12-04T13:26:29Z</dc:date>
    </item>
    <item>
      <title>Re: Error By variables are not properly sorted. But I have already made proc sort step</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Error-By-variables-are-not-properly-sorted-But-I-have-already/m-p/703654#M79935</link>
      <description>&lt;P&gt;Let's step through your program and explain what you should see in the log.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data="....(pathway)....." out=Population;
  by pnr;
run;

Proc print data=Population;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The first step should show a NOTE saying that the dataset WORK.POPULATION has been created with XX observations and YY variables.&amp;nbsp; The second step should print ALL of that dataset to all of your open output destination.&amp;nbsp; This step is NOT needed for the merge to work (or for you to know that the sort worked as the LOG notes will show that.)&lt;/P&gt;
&lt;P&gt;You then repeat the same for a second dataset.&lt;/P&gt;
&lt;P&gt;And your final step is the one that should combine the data.&amp;nbsp; Notice that the two names listed on the MERGE statement must match exactly the two names listed in the OUT= option of the two earlier PROC SORT steps (and the DATA= option of the PROC PRINT steps).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data DTS_Merged_Population;
  merge Population DTSPNR;
  by pnr;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This will also output a note about creating WORK.DTS_MERGED_POPULATION and show how many observations and how many variables.&amp;nbsp; The number of observations and variables will vary based on how the data is structured and how many matches of PNR values there are but there are some bounds we can place.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The minimum number of observations will be the larger of the sizes of the two inputs. The maximum number of observations will be the SUM of the sizes of the two individual datasets, that could happen if none of the value of PNR match between the two datasets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The minimum number of variables will be the larger number from the two input datasets.&amp;nbsp; That would mean that every variable that is in the dataset with the most variables is also in the other dataset.&amp;nbsp; (note if this is the case then perhaps you did not want to merge the data at all, instead perhaps you meant to use the SET statement instead of the MERGE statement so that the two datasets are interleaved by PNR in the new dataset.) The maximum number of variables would be the SUM minus one.&amp;nbsp; That would mean that the only common variable is PNR.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;If you see a NOTE warning that multiple datasets had multiple observations for the same BY group then the is probably NOT the way you want to combine the data.&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Dec 2020 15:11:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Error-By-variables-are-not-properly-sorted-But-I-have-already/m-p/703654#M79935</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-12-04T15:11:40Z</dc:date>
    </item>
    <item>
      <title>Re: Error By variables are not properly sorted. But I have already made proc sort step</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Error-By-variables-are-not-properly-sorted-But-I-have-already/m-p/703673#M79936</link>
      <description>&lt;P&gt;Let's assume you fixed all the earlier errors, including the MERGE statement which should now read:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;merge Population DTSPNR;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The error message about BY variables would not normally occur with a single BY variable (PNR).&amp;nbsp; By any chance, is the code you posted an abbreviation for a more complex program, and you actually are merging by two variables (not just PNR)?&lt;/P&gt;</description>
      <pubDate>Fri, 04 Dec 2020 16:01:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Error-By-variables-are-not-properly-sorted-But-I-have-already/m-p/703673#M79936</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2020-12-04T16:01:22Z</dc:date>
    </item>
    <item>
      <title>Re: Error By variables are not properly sorted. But I have already made proc sort step</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Error-By-variables-are-not-properly-sorted-But-I-have-already/m-p/704080#M79944</link>
      <description>&lt;P&gt;I think the problem might me that I need to run the DTS dataset with another dataset called DTS format, Så that it is formated correctly. But How to I do that. there are no commen variables, but one variable in the format file covers the labels in the DTS file. any suggestions?&lt;/P&gt;</description>
      <pubDate>Mon, 07 Dec 2020 07:49:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Error-By-variables-are-not-properly-sorted-But-I-have-already/m-p/704080#M79944</guid>
      <dc:creator>Jannie_D</dc:creator>
      <dc:date>2020-12-07T07:49:09Z</dc:date>
    </item>
  </channel>
</rss>

