<?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: How to get numeric values and gives order in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-numeric-values-and-gives-order/m-p/718142#M222191</link>
    <description>&lt;P&gt;How about&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID $ Name $;
infile datalines missover;
datalines;
101 Org    
101 Mineel 
101 Ram    
102 23     
102 44     
102 33     
103        
103 40     
103 42     
104        
104 clinic 
104 Dale   
105 12     
105 4      
105 6      
106        
106 Y      
106 N      
107        
108        
;

data want(drop = n i rc flag);

   dcl hash h(ordered : "Y", multidata : "Y");
   h.definekey("n");
   h.definedone();
   dcl hiter hi("h");

   do until (last.ID);
      set have;
      by id;
      n = input(Name, ?? best8.);
      h.add();
      if n then flag = 1;
   end;

   do until (last.ID);
      set have;
      by ID;
      if flag then do i = 1 by 1 while (hi.next() = 0);
         if input(Name, ?? best8.) = n then do;
            new = i;
            rc = hi.last();
            rc = hi.next();
            leave;
         end;
      end;

      output;
   end;

   h.clear();

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;ID   Name   new 
101  Org    . 
101  Mineel . 
101  Ram    . 
102  23     1 
102  44     3 
102  33     2 
103         1 
103  40     2 
103  42     3 
104         . 
104  clinic . 
104  Dale   . 
105  12     3 
105  4      1 
105  6      2 
106         . 
106  Y      . 
106  N      . 
107         . 
108         . &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 10 Feb 2021 08:24:55 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2021-02-10T08:24:55Z</dc:date>
    <item>
      <title>How to get numeric values and gives order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-numeric-values-and-gives-order/m-p/718132#M222183</link>
      <description>&lt;P&gt;Hi Everyone&amp;nbsp;&lt;/P&gt;&lt;P&gt;i have a dataset having variables ID Name new&lt;/P&gt;&lt;P&gt;input like this&lt;BR /&gt;&amp;nbsp;ID&amp;nbsp; &amp;nbsp;Name&amp;nbsp; &amp;nbsp; &amp;nbsp; New&lt;BR /&gt;101&amp;nbsp; Org&lt;BR /&gt;101&amp;nbsp; Mineel&lt;BR /&gt;101&amp;nbsp; Ram&lt;BR /&gt;102&amp;nbsp; 23&lt;BR /&gt;102&amp;nbsp; 44&lt;BR /&gt;102&amp;nbsp; 33&lt;BR /&gt;103&amp;nbsp; &amp;nbsp;&lt;BR /&gt;103&amp;nbsp; 40&lt;BR /&gt;103&amp;nbsp; 42&lt;/P&gt;&lt;P&gt;104&amp;nbsp; &amp;nbsp;&lt;BR /&gt;104&amp;nbsp; clinic&lt;BR /&gt;104&amp;nbsp; Dale&lt;BR /&gt;105&amp;nbsp; 12&lt;BR /&gt;105&amp;nbsp; &amp;nbsp;4&lt;BR /&gt;105&amp;nbsp; &amp;nbsp;6&lt;BR /&gt;106&lt;BR /&gt;106&amp;nbsp; &amp;nbsp;Y&lt;BR /&gt;106&amp;nbsp; &amp;nbsp;N&lt;BR /&gt;107&lt;/P&gt;&lt;P&gt;108&lt;/P&gt;&lt;P&gt;So I need to get numeric values from Name varible and sort the numerical values and store that sorting order in 'New' varible..and if ID value does not contain any value in Name it should not taken as numeric(ID 107,108)..output should be like&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;ID&amp;nbsp; &amp;nbsp;Name&amp;nbsp; &amp;nbsp; &amp;nbsp; New&lt;BR /&gt;101&amp;nbsp; Org&lt;BR /&gt;101&amp;nbsp; Mineel&lt;BR /&gt;101&amp;nbsp; Ram&lt;BR /&gt;102&amp;nbsp; 23&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;BR /&gt;102&amp;nbsp; 44&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&lt;BR /&gt;102&amp;nbsp; 33&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;BR /&gt;103&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;BR /&gt;103&amp;nbsp; 40&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;BR /&gt;103&amp;nbsp; 42&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&lt;/P&gt;&lt;P&gt;104&amp;nbsp; &amp;nbsp;&lt;BR /&gt;104&amp;nbsp; clinic&lt;BR /&gt;104&amp;nbsp; Dale&lt;BR /&gt;105&amp;nbsp; 12&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&lt;BR /&gt;105&amp;nbsp; &amp;nbsp;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;BR /&gt;105&amp;nbsp; &amp;nbsp;6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;BR /&gt;106&lt;BR /&gt;106&amp;nbsp; &amp;nbsp;Y&lt;BR /&gt;106&amp;nbsp; &amp;nbsp;N&lt;BR /&gt;107&lt;/P&gt;&lt;P&gt;108&lt;/P&gt;&lt;P&gt;Could anyone please help me for how to do this job..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Feb 2021 07:19:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-numeric-values-and-gives-order/m-p/718132#M222183</guid>
      <dc:creator>sasuser123123</dc:creator>
      <dc:date>2021-02-10T07:19:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to get numeric values and gives order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-numeric-values-and-gives-order/m-p/718138#M222187</link>
      <description>&lt;P&gt;Try next code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp;
 set have;
      name_num = input(name, ?? best8.); /* adapt to max length of NAME */
run;
proc sort data=temp; by ID name_num; run;
data want;
 set temp;
   by ID;
       retain new_var;
        if first.ID then new_var=.;
        if name_num &amp;gt; 0 then naew_var+1;
        drop name_num;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 10 Feb 2021 07:33:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-numeric-values-and-gives-order/m-p/718138#M222187</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2021-02-10T07:33:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to get numeric values and gives order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-numeric-values-and-gives-order/m-p/718142#M222191</link>
      <description>&lt;P&gt;How about&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID $ Name $;
infile datalines missover;
datalines;
101 Org    
101 Mineel 
101 Ram    
102 23     
102 44     
102 33     
103        
103 40     
103 42     
104        
104 clinic 
104 Dale   
105 12     
105 4      
105 6      
106        
106 Y      
106 N      
107        
108        
;

data want(drop = n i rc flag);

   dcl hash h(ordered : "Y", multidata : "Y");
   h.definekey("n");
   h.definedone();
   dcl hiter hi("h");

   do until (last.ID);
      set have;
      by id;
      n = input(Name, ?? best8.);
      h.add();
      if n then flag = 1;
   end;

   do until (last.ID);
      set have;
      by ID;
      if flag then do i = 1 by 1 while (hi.next() = 0);
         if input(Name, ?? best8.) = n then do;
            new = i;
            rc = hi.last();
            rc = hi.next();
            leave;
         end;
      end;

      output;
   end;

   h.clear();

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;ID   Name   new 
101  Org    . 
101  Mineel . 
101  Ram    . 
102  23     1 
102  44     3 
102  33     2 
103         1 
103  40     2 
103  42     3 
104         . 
104  clinic . 
104  Dale   . 
105  12     3 
105  4      1 
105  6      2 
106         . 
106  Y      . 
106  N      . 
107         . 
108         . &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Feb 2021 08:24:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-numeric-values-and-gives-order/m-p/718142#M222191</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-02-10T08:24:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to get numeric values and gives order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-numeric-values-and-gives-order/m-p/718144#M222193</link>
      <description>&lt;P&gt;Im not getting desired output, in Id 103 first value is missing it should take it as 1 in new variable but it takes from next value of NAME variable of 103&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Feb 2021 08:00:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-numeric-values-and-gives-order/m-p/718144#M222193</guid>
      <dc:creator>sasuser123123</dc:creator>
      <dc:date>2021-02-10T08:00:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to get numeric values and gives order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-numeric-values-and-gives-order/m-p/718148#M222195</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/282134"&gt;@sasuser123123&lt;/a&gt;&amp;nbsp;just made a correction to my code below. This gives you the exact result you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let me know if this works for you.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Feb 2021 08:18:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-numeric-values-and-gives-order/m-p/718148#M222195</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-02-10T08:18:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to get numeric values and gives order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-numeric-values-and-gives-order/m-p/718157#M222198</link>
      <description>&lt;P&gt;Yeah its working . i applied the same code to another dataset which contains&amp;nbsp;start values like&lt;/P&gt;&lt;P&gt;107413601&lt;/P&gt;&lt;P&gt;107415618&lt;/P&gt;&lt;P&gt;87896111&lt;/P&gt;&lt;P&gt;so the code will give the output to this values is&amp;nbsp;&lt;/P&gt;&lt;P&gt;1&lt;/P&gt;&lt;P&gt;2&lt;/P&gt;&lt;P&gt;3&amp;nbsp;&lt;/P&gt;&lt;P&gt;I dont know why its coming like&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and also I have 0 in Id variable the code not giving the sorting order for 0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;could you please help me out&lt;/P&gt;</description>
      <pubDate>Wed, 10 Feb 2021 09:03:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-numeric-values-and-gives-order/m-p/718157#M222198</guid>
      <dc:creator>sasuser123123</dc:creator>
      <dc:date>2021-02-10T09:03:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to get numeric values and gives order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-numeric-values-and-gives-order/m-p/718158#M222199</link>
      <description>&lt;P&gt;In above comment its not start its ID(sorry for mistake)&lt;/P&gt;</description>
      <pubDate>Wed, 10 Feb 2021 09:04:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-numeric-values-and-gives-order/m-p/718158#M222199</guid>
      <dc:creator>sasuser123123</dc:creator>
      <dc:date>2021-02-10T09:04:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to get numeric values and gives order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-numeric-values-and-gives-order/m-p/718159#M222200</link>
      <description>&lt;P&gt;Please post data that is representable of you actual data. Makes it easier to help you &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Feb 2021 09:04:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-numeric-values-and-gives-order/m-p/718159#M222200</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-02-10T09:04:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to get numeric values and gives order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-numeric-values-and-gives-order/m-p/718162#M222202</link>
      <description>&lt;P&gt;&lt;BR /&gt;ID Name&amp;nbsp;&lt;BR /&gt;112 Org&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;112 Mineel&lt;BR /&gt;112 Ram&lt;BR /&gt;113 23&amp;nbsp;&lt;BR /&gt;113 44&amp;nbsp;&lt;BR /&gt;113 33&amp;nbsp;&lt;BR /&gt;114 10741368&lt;BR /&gt;114 10741568&amp;nbsp;&lt;BR /&gt;114 8789611&lt;/P&gt;&lt;P&gt;115&amp;nbsp; 0&lt;BR /&gt;115&amp;nbsp; 0&lt;BR /&gt;116 12&amp;nbsp;&lt;BR /&gt;116 4&amp;nbsp;&amp;nbsp;&lt;BR /&gt;116 6&amp;nbsp;&lt;BR /&gt;so&amp;nbsp; Im geting wrong sorting order for id 114 and didi not get any number for 115&lt;/P&gt;</description>
      <pubDate>Wed, 10 Feb 2021 09:16:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-numeric-values-and-gives-order/m-p/718162#M222202</guid>
      <dc:creator>sasuser123123</dc:creator>
      <dc:date>2021-02-10T09:16:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to get numeric values and gives order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-numeric-values-and-gives-order/m-p/718168#M222206</link>
      <description>&lt;P&gt;Seem to me that the result for 114 is correct?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regarding 115, just made a correction. See if this helps.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID $ Name $;
infile datalines missover;
datalines; 
112  Org      
112  Mineel   
112  Ram      
113  23       
113  44       
113  33       
114  10741368 
114  10741568 
114  8789611  
115  0        
115  0        
116  12       
116  4        
116  6        
;

data want(drop = n flag i rc);

   dcl hash h(ordered : "Y", multidata : "Y");
   h.definekey("n");
   h.definedone();
   dcl hiter hi("h");

   do until (last.ID);
      set have;
      by id;
      n = input(Name, ?? best8.);
      h.add();
      if n &amp;gt; . then flag = 1;
   end;

   do until (last.ID);
      set have;
      by ID;
      if flag then do i = 1 by 1 while (hi.next() = 0);
         if input(Name, ?? best8.) = n then do;
            new = i;
            rc = hi.last();
            rc = hi.next();
            leave;
         end;
      end;

      output;
   end;

   h.clear();

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;ID   Name      new 
112  Org       . 
112  Mineel    . 
112  Ram       . 
113  23        1 
113  44        3 
113  33        2 
114  10741368  2 
114  10741568  3 
114  8789611   1 
115  0         1 
115  0         1 
116  12        3 
116  4         1 
116  6         2 
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Feb 2021 10:39:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-numeric-values-and-gives-order/m-p/718168#M222206</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-02-10T10:39:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to get numeric values and gives order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-numeric-values-and-gives-order/m-p/718174#M222209</link>
      <description>Im unable to understand this code and also not getting any other methods..&lt;BR /&gt;could you please help me out</description>
      <pubDate>Wed, 10 Feb 2021 10:32:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-numeric-values-and-gives-order/m-p/718174#M222209</guid>
      <dc:creator>sasuser123123</dc:creator>
      <dc:date>2021-02-10T10:32:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to get numeric values and gives order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-numeric-values-and-gives-order/m-p/718176#M222210</link>
      <description>&lt;P&gt;Does my code provide the result you want?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The logic in your problem is not trivial, so the code probably will not be either &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; I'll help you understand the code.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Feb 2021 10:41:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-numeric-values-and-gives-order/m-p/718176#M222210</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-02-10T10:41:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to get numeric values and gives order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-numeric-values-and-gives-order/m-p/718177#M222211</link>
      <description>Yes it works..but for few observations it's not working I have dataset with 350 observations out of that 330 observations got expected sorting number but for remaining 20 observations the sorting order is not coming expectedly. I don't know why.&lt;BR /&gt;and 20 observations'S NAME have values like&lt;BR /&gt;10456788&lt;BR /&gt;10425786&lt;BR /&gt;887446&lt;BR /&gt;&lt;BR /&gt;It gives sorting order 1,2,3... etc per ID</description>
      <pubDate>Wed, 10 Feb 2021 10:58:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-numeric-values-and-gives-order/m-p/718177#M222211</guid>
      <dc:creator>sasuser123123</dc:creator>
      <dc:date>2021-02-10T10:58:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to get numeric values and gives order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-numeric-values-and-gives-order/m-p/718200#M222223</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/282134"&gt;@sasuser123123&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Im not getting desired output, in Id 103 first value is missing it should take it as 1 in new variable but it takes from next value of NAME variable of 103&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;You did not define the exact rules when to count the rows per ID and when to leave it blank.&lt;/P&gt;
&lt;P&gt;According to your output shown data I'm trying to define those rules:&lt;/P&gt;
&lt;P&gt;1) If &lt;STRONG&gt;none&lt;/STRONG&gt; of the names per ID is a number then leave the new variable &lt;STRONG&gt;blank&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;2) If &lt;STRONG&gt;all&lt;/STRONG&gt; names per ID are &lt;STRONG&gt;numbers&lt;/STRONG&gt; or part of then are empty then &lt;STRONG&gt;count&lt;/STRONG&gt; into the new variable.&lt;/P&gt;
&lt;P&gt;3) If &lt;STRONG&gt;all&lt;/STRONG&gt; names per ID are &lt;STRONG&gt;empty&lt;/STRONG&gt; then leave the new variable &lt;STRONG&gt;blank&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;4) Question - Can it be that some names are alphabetic and others are numeric in the same ID?&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;If positive - what should be the rule ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code&amp;nbsp;&lt;STRONG&gt;name_num = input(name,?? best 8.)&lt;/STRONG&gt; will result in:&lt;/P&gt;
&lt;P&gt;- for empty name or alphabetic (or alphanumeric) it will result into a missing value&lt;/P&gt;
&lt;P&gt;- for a number it will result into a numeric variable with the same value&lt;/P&gt;
&lt;P&gt;Thus by computing the max value got per ID it is possible to make a decision :&lt;/P&gt;
&lt;P&gt;- if max value is missing value then leave it blank&lt;/P&gt;
&lt;P&gt;- otherwise count starting with 1 and save it in the new variable after sort by ID NAME.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Next is the code to do it:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp;
 set have;
      name_num = input(name, ?? best8.); /* adapt to max length of NAME */
run;
proc sort data=temp; by ID name_num; run;

proc sql;
  create table tmp2 as
  select ID,
         max(name_num) as flag
  from temp
  group by ID
  order by ID;
quit;

options missing= ' ';
data want; 
 merge temp tmp2;
  by ID;
     retain new_var;
     if first.ID then do;
        if missing(flag) then new_var = flag;
		else new_var = 1;
     end; else if flag then new_var+1;
     drop flag;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you find IDs with wrong counting please post:&lt;/P&gt;
&lt;P&gt;1) The ID and NAMEs of that ID&lt;/P&gt;
&lt;P&gt;2) Explain the logic why it is wrong and what rule it shall follow.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Feb 2021 12:03:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-numeric-values-and-gives-order/m-p/718200#M222223</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2021-02-10T12:03:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to get numeric values and gives order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-numeric-values-and-gives-order/m-p/718277#M222258</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/282134"&gt;@sasuser123123&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Yes it works..but for few observations it's not working I have dataset with 350 observations out of that 330 observations got expected sorting number but for remaining 20 observations the sorting order is not coming expectedly. I don't know why.&lt;BR /&gt;and 20 observations'S NAME have values like&lt;BR /&gt;10456788&lt;BR /&gt;10425786&lt;BR /&gt;887446&lt;BR /&gt;&lt;BR /&gt;It gives sorting order 1,2,3... etc per ID&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;When you mix numerals in character variables the sort order is very likely not what you expect and you may need to provide which you expect for a sort order.&lt;/P&gt;
&lt;P&gt;"102456788" comes before "887446" because character sort order defaults to comparing the first CHARACTER value to the first character of another value and "1" comes before "8".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think that for your purpose you need to 1) identify those "name" values that are all digits; 2) subset the data on that; 3) use Proc Sort on the subset of names with SORTSEQ=linguistic(numeric_collation=on) option to sort in "numeric" order; 4) add the order and 5) merge back to the original data&lt;/P&gt;</description>
      <pubDate>Wed, 10 Feb 2021 15:46:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-numeric-values-and-gives-order/m-p/718277#M222258</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-02-10T15:46:05Z</dc:date>
    </item>
  </channel>
</rss>

