<?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 Sort is removing leading numbers in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Sort-is-removing-leading-numbers/m-p/857141#M338652</link>
    <description>&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am having an issue with my data steps removing leading 1's from my variable, for example test.prov2 is being sorted by key which I need the dataset sorted by (test.prov2) but in that case the id is losing the leading 1's. How do I not remove the 1's (from variable key)when sorting or merging? Example is attached i want to keep the 1;s in key but they are being dropped.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sort data=test.prov2 ;&lt;BR /&gt;by key;&lt;BR /&gt;format id $20.;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc sort data=test1.prov;&lt;BR /&gt;by key;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data hce.provider_merge5;&lt;BR /&gt;merge test.prov2 test1.prov;&lt;BR /&gt;length id $20;&lt;BR /&gt;by key;&lt;BR /&gt;run;&lt;/P&gt;</description>
    <pubDate>Sat, 04 Feb 2023 05:18:35 GMT</pubDate>
    <dc:creator>Rsadiq</dc:creator>
    <dc:date>2023-02-04T05:18:35Z</dc:date>
    <item>
      <title>Sort is removing leading numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sort-is-removing-leading-numbers/m-p/857141#M338652</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am having an issue with my data steps removing leading 1's from my variable, for example test.prov2 is being sorted by key which I need the dataset sorted by (test.prov2) but in that case the id is losing the leading 1's. How do I not remove the 1's (from variable key)when sorting or merging? Example is attached i want to keep the 1;s in key but they are being dropped.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sort data=test.prov2 ;&lt;BR /&gt;by key;&lt;BR /&gt;format id $20.;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc sort data=test1.prov;&lt;BR /&gt;by key;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data hce.provider_merge5;&lt;BR /&gt;merge test.prov2 test1.prov;&lt;BR /&gt;length id $20;&lt;BR /&gt;by key;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Sat, 04 Feb 2023 05:18:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sort-is-removing-leading-numbers/m-p/857141#M338652</guid>
      <dc:creator>Rsadiq</dc:creator>
      <dc:date>2023-02-04T05:18:35Z</dc:date>
    </item>
    <item>
      <title>Re: Sort is removing leading numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sort-is-removing-leading-numbers/m-p/857143#M338654</link>
      <description>&lt;P&gt;PROC SORT will not change any data in variables, it will only reorder observations and, if NODUPKEY is used, remove complete observations. There will not be any change to the content of variables.&lt;BR /&gt;Are you sure that id is only contained in dataset prov2?&lt;/P&gt;</description>
      <pubDate>Sat, 04 Feb 2023 07:20:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sort-is-removing-leading-numbers/m-p/857143#M338654</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-02-04T07:20:01Z</dc:date>
    </item>
    <item>
      <title>Re: Sort is removing leading numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sort-is-removing-leading-numbers/m-p/857146#M338656</link>
      <description>&lt;P&gt;As already mentioned Proc Sort doesn't change values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't understand how the attached document shows the issue you're describing.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just having a theory: If you move the length statement before the merge statement does the issue still persist?&amp;nbsp; ....and do you get truncation warnings in the SAS log?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data hce.provider_merge5;
length id $20;
merge test.prov2 test1.prov;
by key;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 04 Feb 2023 08:16:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sort-is-removing-leading-numbers/m-p/857146#M338656</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-02-04T08:16:03Z</dc:date>
    </item>
    <item>
      <title>Re: Sort is removing leading numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sort-is-removing-leading-numbers/m-p/857165#M338671</link>
      <description>For example the document shows that it is 111111n for example but after sorting the result shows n for id. It truncates the 1's for some reason. I just wanted to see how to fix that since I need the full ID</description>
      <pubDate>Sat, 04 Feb 2023 14:43:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sort-is-removing-leading-numbers/m-p/857165#M338671</guid>
      <dc:creator>Rsadiq</dc:creator>
      <dc:date>2023-02-04T14:43:14Z</dc:date>
    </item>
    <item>
      <title>Re: Sort is removing leading numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sort-is-removing-leading-numbers/m-p/857166#M338672</link>
      <description>&lt;P&gt;For example after the sort&amp;nbsp;&lt;/P&gt;&lt;P&gt;the below data step , i see the attached instead of the 1111s in front of the id, it shows just characters and letters. but i need the ones, why would the ones disapper in the datastep?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sort data=prov2 ;&lt;BR /&gt;by key;&lt;BR /&gt;format id $20.;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Sat, 04 Feb 2023 15:21:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sort-is-removing-leading-numbers/m-p/857166#M338672</guid>
      <dc:creator>Rsadiq</dc:creator>
      <dc:date>2023-02-04T15:21:06Z</dc:date>
    </item>
    <item>
      <title>Re: Sort is removing leading numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sort-is-removing-leading-numbers/m-p/857167#M338673</link>
      <description>&lt;P&gt;For example after the sort&amp;nbsp;&lt;/P&gt;&lt;P&gt;the below data step , i see the attached instead of the 1111s in front of the id, it shows just characters and letters. but i need the ones, why would the ones disappear in the datastep?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sort data=prov2 ;&lt;BR /&gt;by key;&lt;BR /&gt;format id $20.;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Sat, 04 Feb 2023 15:24:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sort-is-removing-leading-numbers/m-p/857167#M338673</guid>
      <dc:creator>Rsadiq</dc:creator>
      <dc:date>2023-02-04T15:24:39Z</dc:date>
    </item>
    <item>
      <title>Re: Sort is removing leading numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sort-is-removing-leading-numbers/m-p/857169#M338674</link>
      <description>&lt;P&gt;Remove the format statement. Run a PROC PRINT before and after the sort, then post the results here.&lt;/P&gt;
&lt;P&gt;Do not attach Office documents; you can post the screenshot directly, using the camera icon.&lt;/P&gt;</description>
      <pubDate>Sat, 04 Feb 2023 15:36:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sort-is-removing-leading-numbers/m-p/857169#M338674</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-02-04T15:36:46Z</dc:date>
    </item>
    <item>
      <title>Re: Sort is removing leading numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sort-is-removing-leading-numbers/m-p/857172#M338675</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Rsadiq_0-1675525299765.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/80098iDF26148B45AAF7F6/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Rsadiq_0-1675525299765.png" alt="Rsadiq_0-1675525299765.png" /&gt;&lt;/span&gt;showing before here (before the sort on key) the ids have 111's&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;after the sort this happens, the 1's vanish and only whatever is left after the 1's appears&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Rsadiq_1-1675525354519.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/80099i15C65710E8DF6AD6/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Rsadiq_1-1675525354519.png" alt="Rsadiq_1-1675525354519.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 04 Feb 2023 15:42:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sort-is-removing-leading-numbers/m-p/857172#M338675</guid>
      <dc:creator>Rsadiq</dc:creator>
      <dc:date>2023-02-04T15:42:58Z</dc:date>
    </item>
    <item>
      <title>Re: Sort is removing leading numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sort-is-removing-leading-numbers/m-p/857174#M338676</link>
      <description>&lt;P&gt;Run this (and&amp;nbsp;&lt;STRONG&gt;ONLY&lt;/STRONG&gt; this!):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc print data=test.prov2 (obs=10);
run;

proc sort
  data=test.prov2 (obs=10)
  out=prov2_test
;
by key;
run;

proc print data=prov2_test;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Post the complete log of the code by copy/pasting it into a window opened with this button:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Bildschirmfoto 2020-04-07 um 08.32.59.jpg" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/54552i914D97BE1B0F21E5/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Bildschirmfoto 2020-04-07 um 08.32.59.jpg" alt="Bildschirmfoto 2020-04-07 um 08.32.59.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Also post the result of both PRINTs in one screenshot.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 04 Feb 2023 15:54:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sort-is-removing-leading-numbers/m-p/857174#M338676</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-02-04T15:54:26Z</dc:date>
    </item>
    <item>
      <title>Re: Sort is removing leading numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sort-is-removing-leading-numbers/m-p/857177#M338678</link>
      <description>&lt;P&gt;Sorting just changes the order.&amp;nbsp;&amp;nbsp;Since you are sorting by KEY and not by ID the location of the values of ID that start with 111 will be potentially be different than before.&amp;nbsp; Did you search the whole file for them?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But the NODUPKEY option will remove OBSERVATIONS.&amp;nbsp; So it is possible the observations with values of ID that start with 111 were deleted because there was already some other observation with that same value of KEY that was kept.&lt;/P&gt;</description>
      <pubDate>Sat, 04 Feb 2023 15:58:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sort-is-removing-leading-numbers/m-p/857177#M338678</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-02-04T15:58:37Z</dc:date>
    </item>
    <item>
      <title>Re: Sort is removing leading numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sort-is-removing-leading-numbers/m-p/857182#M338682</link>
      <description>&lt;PRE&gt;                                                         The SAS System                           09:09 Saturday, February 4, 2023

1          ;*';*";*/;quit;run;
2          OPTIONS PAGENO=MIN;
3          %LET _CLIENTTASKLABEL='Program';
4          %LET _CLIENTPROCESSFLOWNAME='Process Flow';
5          %LET _CLIENTPROJECTPATH='';
6          %LET _CLIENTPROJECTPATHHOST='';
7          %LET _CLIENTPROJECTNAME='';
8          %LET _SASPROGRAMFILE='';
9          %LET _SASPROGRAMFILEHOST='';
10         
11         ODS _ALL_ CLOSE;
12         OPTIONS DEV=ACTIVEX;
13         GOPTIONS XPIXELS=0 YPIXELS=0;
14         FILENAME EGSR TEMP;
15         ODS tagsets.sasreport13(ID=EGSR) FILE=EGSR
16             STYLE=HtmlBlue
17             STYLESHEET=(URL="file:///C:/Program%20Files%20(x86)/SAS94/x86/SASEnterpriseGuide/7.1/Styles/HtmlBlue.css")
18             NOGTITLE
19             NOGFOOTNOTE
20             GPATH=&amp;amp;sasworklocation
21             ENCODING=UTF8
22             options(rolap="on")
23         ;
NOTE: Writing TAGSETS.SASREPORT13(EGSR) Body file: EGSR
24         
25         GOPTIONS ACCESSIBLE;
26         proc print data=test.prov2 (obs=10) ;
27         run;

NOTE: There were 10 observations read from the data set test.PROV2.
NOTE: PROCEDURE PRINT used (Total process time):
      real time           0.00 seconds
      user cpu time       0.00 seconds
      system cpu time     0.01 seconds
      memory              1459.31k
      OS Memory           25776.00k
      Timestamp           02/04/2023 10:04:27 AM
      Step Count                        25  Switch Count  0
      Page Faults                       0
      Page Reclaims                     298
      Page Swaps                        0
      Voluntary Context Switches        5
      Involuntary Context Switches      0
      Block Input Operations            0
      Block Output Operations           0
      

28         
29         proc sort
30           data=test.prov2 (obs=10)
31           out=prov2_test
32         ;
33         by key;
34         run;

NOTE: There were 10 observations read from the data set test.PROV2.
NOTE: The data set WORK.PROV2_TEST has 10 observations and 2 variables.
NOTE: PROCEDURE SORT used (Total process time):
2                                                          The SAS System                           09:09 Saturday, February 4, 2023

      real time           0.00 seconds
      user cpu time       0.00 seconds
      system cpu time     0.00 seconds
      memory              1293.62k
      OS Memory           25776.00k
      Timestamp           02/04/2023 10:04:27 AM
      Step Count                        26  Switch Count  2
      Page Faults                       0
      Page Reclaims                     143
      Page Swaps                        0
      Voluntary Context Switches        35
      Involuntary Context Switches      0
      Block Input Operations            0
      Block Output Operations           0
      

35         
36         proc print data=prov2_test ;
37         run;

NOTE: There were 10 observations read from the data set WORK.PROV2_TEST.
NOTE: PROCEDURE PRINT used (Total process time):
      real time           0.00 seconds
      user cpu time       0.01 seconds
      system cpu time     0.00 seconds
      memory              340.03k
      OS Memory           25260.00k
      Timestamp           02/04/2023 10:04:27 AM
      Step Count                        27  Switch Count  0
      Page Faults                       0
      Page Reclaims                     32
      Page Swaps                        0
      Voluntary Context Switches        0
      Involuntary Context Switches      0
      Block Input Operations            0
      Block Output Operations           0
      

38         
39         GOPTIONS NOACCESSIBLE;
40         %LET _CLIENTTASKLABEL=;
41         %LET _CLIENTPROCESSFLOWNAME=;
42         %LET _CLIENTPROJECTPATH=;
43         %LET _CLIENTPROJECTPATHHOST=;
44         %LET _CLIENTPROJECTNAME=;
45         %LET _SASPROGRAMFILE=;
46         %LET _SASPROGRAMFILEHOST=;
47         
48         ;*';*";*/;quit;run;
49         ODS _ALL_ CLOSE;
50         
51         
52         QUIT; RUN;
53         &lt;/PRE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Rsadiq_0-1675526850090.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/80101i8911EE9BE151D36B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Rsadiq_0-1675526850090.png" alt="Rsadiq_0-1675526850090.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;DIV&gt;115Obs prov_id PROVIDER_KEY &lt;TABLE cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;11&lt;/TD&gt;&lt;TD&gt;55&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;111&lt;/TD&gt;&lt;TD&gt;555&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;1111&lt;/TD&gt;&lt;TD&gt;5555&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;11111&lt;/TD&gt;&lt;TD&gt;55555&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;111111&lt;/TD&gt;&lt;TD&gt;555555&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;TD&gt;111111d&lt;/TD&gt;&lt;TD&gt;5555551&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;111111a&lt;/TD&gt;&lt;TD&gt;5555554&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;9&lt;/TD&gt;&lt;TD&gt;1111111&lt;/TD&gt;&lt;TD&gt;5555555&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;TD&gt;1111113&lt;/TD&gt;&lt;TD&gt;5555556&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/DIV&gt;&lt;P&gt;results from both, i tried your code with a higher number of obs for example 200 and it truncates the 1's again but this logic is working for the obs=10&lt;/P&gt;</description>
      <pubDate>Sat, 04 Feb 2023 16:10:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sort-is-removing-leading-numbers/m-p/857182#M338682</guid>
      <dc:creator>Rsadiq</dc:creator>
      <dc:date>2023-02-04T16:10:51Z</dc:date>
    </item>
    <item>
      <title>Re: Sort is removing leading numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sort-is-removing-leading-numbers/m-p/857183#M338683</link>
      <description>&lt;P&gt;My code proves that no truncation occurs, but the output clearly shows you have variable value lengths. Don't be surprised that the sort puts other (shorter) values to the top of the dataset when sorting more of the dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 04 Feb 2023 16:18:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sort-is-removing-leading-numbers/m-p/857183#M338683</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-02-04T16:18:08Z</dc:date>
    </item>
    <item>
      <title>Re: Sort is removing leading numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sort-is-removing-leading-numbers/m-p/857186#M338686</link>
      <description>&lt;P&gt;If you merge two tables that have same named variables that are not part of the merge key then the value from the table listed last in the merge statement will "win".&lt;/P&gt;
&lt;P&gt;I've renamed in below merge the id variables so they individual names per source table. Investigate the result and see if this explains to you where these "leading 1" went. It's certainly not a truncation issue and it certainly has nothing to do with a Proc Sort that never changes values.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=test.prov2;
  by key;
run;

proc sort data=test1.prov;
  by key;
run;

data hce.provider_merge5;
  length id $20;
  merge test.prov2(rename=(id=id2)) test1.prov(rename=(id=id1));
  by key;
  if id1 ne id2 then output;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 04 Feb 2023 16:35:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sort-is-removing-leading-numbers/m-p/857186#M338686</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-02-04T16:35:31Z</dc:date>
    </item>
    <item>
      <title>Re: Sort is removing leading numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sort-is-removing-leading-numbers/m-p/857191#M338691</link>
      <description>&lt;P&gt;yes but when i remove the obs statement from the steps , the id gets truncated in the end table. I did do a search to see if the 11's are somewhere else in the table in the ids but there is none. It does look like truncation is going on. I am just confused on why and how.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 04 Feb 2023 17:37:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sort-is-removing-leading-numbers/m-p/857191#M338691</guid>
      <dc:creator>Rsadiq</dc:creator>
      <dc:date>2023-02-04T17:37:17Z</dc:date>
    </item>
    <item>
      <title>Re: Sort is removing leading numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sort-is-removing-leading-numbers/m-p/857192#M338692</link>
      <description>&lt;P&gt;I don't understand what you mean by "truncates the 1's".&amp;nbsp; You clearly have values that have different numbers of the digit 1 in the front of them.&amp;nbsp; Your two printouts are also showing different alignments of the values.&amp;nbsp; The first table (the photograph you pasted in of your output) is showing the second column right aligned, like a numeric variable would be.&amp;nbsp; But the second table (the html table you pasted in) is showing the second column left aligned like SAS would show a character variable.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Remember that ODS output "eats" the leading spaces.&amp;nbsp;&lt;/STRONG&gt;&amp;nbsp;So if the first column has leading spaces then the HTML output like you seem to be showing will not show them.&amp;nbsp; Regular LISTING output will show the leading spaces in PROC PRINT output.&amp;nbsp; You can use the $QUOTE format with your character variable to have ODS output preserve the leading spaces since they will be enclosed in quotes. So you can see the difference between "111" and "&amp;nbsp; &amp;nbsp;111" and why the second one would sort before the first.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But if you are actually merging two datasets by KEY and they both contain the variable ID then the value retained will be the one read last.&amp;nbsp; In a normal one-to-one merge that means the last dataset listed "wins".&amp;nbsp; But in a one-to-many or many-to-many merge it gets more complicated as datasets that have run out of observations for that value of the KEY variable are no longer being read in, so they do not overwrite the values read from the other dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 04 Feb 2023 17:38:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sort-is-removing-leading-numbers/m-p/857192#M338692</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-02-04T17:38:07Z</dc:date>
    </item>
    <item>
      <title>Re: Sort is removing leading numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sort-is-removing-leading-numbers/m-p/857195#M338693</link>
      <description>&lt;P&gt;for example like i am sorting by key, result is as shown&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Rsadiq_0-1675533460748.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/80102i601284B2D97F77F2/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Rsadiq_0-1675533460748.png" alt="Rsadiq_0-1675533460748.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but if im sorting by id, the 1's dont vanish why is that the case? Like 11111z is being transformed to just z. After doing a simple sort. This issue is not being solved. why is the id being truncated when i sort by key, when i sort by id it stays (the leading 1's)&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Rsadiq_1-1675533534485.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/80103i7954894692817CDE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Rsadiq_1-1675533534485.png" alt="Rsadiq_1-1675533534485.png" /&gt;&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>Sat, 04 Feb 2023 18:01:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sort-is-removing-leading-numbers/m-p/857195#M338693</guid>
      <dc:creator>Rsadiq</dc:creator>
      <dc:date>2023-02-04T18:01:20Z</dc:date>
    </item>
    <item>
      <title>Re: Sort is removing leading numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sort-is-removing-leading-numbers/m-p/857197#M338694</link>
      <description>&lt;P&gt;You seem be comparing apples to oranges.&amp;nbsp; Your first photograph has one variable. Your second photograph has two variables.&amp;nbsp;You cropped out the variable names when you took the picture of your screen so we cannot even tell if they are of the same variables.&amp;nbsp; And we do not know the names of the dataset used to make either picture.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is it that you are comparing?&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why not just look for ONE of the values that you thing is gone?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if the variable in the first picture is named ID and the dataset is named HAVE then you can run this code to see the values of ID and KEY for the observations where ID has a value that would probably appear as 111 on your screen.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc print data=have;
  var id key ;
  where strip(id)='111';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Sort by a variable will definitely change the order that the values appear.&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input id :$10. key ;
cards;
1     9
11    8
111   7
1111  6
2     5
234   4
;

proc sort data=have; by id; run;
proc print; run;
proc sort data=have; by key; run;
proc print; run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1675534929777.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/80104i1B318243C2565FDC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1675534929777.png" alt="Tom_0-1675534929777.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 04 Feb 2023 18:22:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sort-is-removing-leading-numbers/m-p/857197#M338694</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-02-04T18:22:22Z</dc:date>
    </item>
    <item>
      <title>Re: Sort is removing leading numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sort-is-removing-leading-numbers/m-p/857198#M338695</link>
      <description>&lt;P&gt;Sorting is not your problem.&amp;nbsp; If you have a problem it is probably caused by MERGING.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your first posted this code :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=test.prov2 ;
by key;
format id $20.;
run;

proc sort data=test1.prov;
by key;
run;

data hce.provider_merge5;
merge test.prov2 test1.prov;
length id $20;
by key;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;There are two mistakes in the code.&amp;nbsp; First is the addition of a FORMAT statement in the first PROC SORT.&amp;nbsp; That will not impact the sorting, but it might impact what the values look like when you display them.&amp;nbsp; By attaching the $20. format specification to the ID variable in the TEST.PROV2 dataset you will not see anything in the variable past the first 20 bytes.&amp;nbsp; So if ID have a length that is longer than 20 some values will be truncated WHEN DISPLAYED.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The second is the LENGTH statement in the data step.&amp;nbsp; Where it is placed it does nothing.&amp;nbsp; If ID was already on TEST.PROV2 (you should have a WARNING in the SAS Log on the first PROC SORT if it does not exist) then its length in HCE. PROVIDER_MERGE5 will be set by the length it has in TEST.PROV2.&amp;nbsp; And if it is not in TEST.PROV2 then its length will be set by the length it has in TEST1.PROV.&amp;nbsp; Only if it is not in either will the LENGTH statement do anything. And what it will do is create an empty character variable named ID.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are really seeing values of ID that exist in the TEST.PROV2 dataset and do not exist in the HCE.PROVIDER_MERGE5 dataset then that is because the value of ID was overwritten by the value of ID read from the TEST1.PROV dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So please tell use information about your two input datasets.&amp;nbsp; Do both datasets have KEY and ID variables?&amp;nbsp; What TYPE of variables are they in each dataset? Are they NUMERIC or CHARACTER.&amp;nbsp; And if they are character what is the LENGTH of the variable?&amp;nbsp; Do any of the variables have any formats permanently attached to them in either dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If ID exists on both datasets then the MERGE will have trouble.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First, as has been explained before, since the value of ID from TEST1.PROV will overwrite the values of ID from TEST.PROV2 for matching values of KEY.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second it ID is defined LONGER in TEST1.PROV than in TEST.PROV2 then values read from TEST1.PROV could be truncated. But that would be right truncation, the ends of the values would be removed, not the beginnings.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So the most likely cause of values disappearing (or changing) is because you asked SAS to replace the values of ID in TEST.PROV2 with the value of ID from TEST1.PROV instead.&lt;/P&gt;</description>
      <pubDate>Sat, 04 Feb 2023 19:34:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sort-is-removing-leading-numbers/m-p/857198#M338695</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-02-04T19:34:34Z</dc:date>
    </item>
    <item>
      <title>Re: Sort is removing leading numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sort-is-removing-leading-numbers/m-p/857200#M338696</link>
      <description>&lt;P&gt;Post your .sas7bdat file as an attachment. It is in the data, so we must see it.&lt;/P&gt;</description>
      <pubDate>Sat, 04 Feb 2023 19:21:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sort-is-removing-leading-numbers/m-p/857200#M338696</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-02-04T19:21:07Z</dc:date>
    </item>
    <item>
      <title>Re: Sort is removing leading numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sort-is-removing-leading-numbers/m-p/857275#M338746</link>
      <description>&lt;P&gt;Hello &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/133811"&gt;@Rsadiq&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;Please provide a sample of your data as sas7bdat file?&lt;/P&gt;</description>
      <pubDate>Sun, 05 Feb 2023 18:51:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sort-is-removing-leading-numbers/m-p/857275#M338746</guid>
      <dc:creator>Sajid01</dc:creator>
      <dc:date>2023-02-05T18:51:40Z</dc:date>
    </item>
  </channel>
</rss>

