Home Forums Main Forums SAS Forum SortN and SortC call routines in SAS

  • SortN and SortC call routines in SAS

     Datura updated 7 months, 1 week ago 1 Member · 1 Post
  • Datura

    Member
    February 7, 2021 at 3:24 pm

    These two call routines (not functions) came into existence since SAS9.0. They are used to sort the values of a list of variables passed to it. SortN is to sort numeric values, while SortC for character values. If the values belong to an array, then these routines effectively sort the values of the array.

    Run below code in SAS to see how it works.

    data A;
    input Area $ province $ city $ A B C D ;
    cards;
    South Henan Luoyang 20 33 69 58
    South Henan Zhengzhou 78 33 44 77 96
    East Henan Kaifeng 27 87 21 54
    West Henan Luoyang 64 68 37 93
    North Henan Kaifeng 54 67 19 78
    East Jiangsu Nanjing 45 47 84 65
    East Jiangsu Nanjing 68 74 39 82
    West Jiangsu Suzhou 100 39 58 71
    South . Xinxiang 49 87 69 39
    South . Xinxiang 30 20 50 60
    South . Kaifeng 23 11 58 69
    East Jiangsu . 21 33 59 67
    West Jiangsu Nanjing 100 . 500 .
    ;
    run;

    data S;
    set A;
    call sortn (A, B, C, D);
    put A= B= C= D=;
    put D= C= B= A=;
    put '===============================';
    run;

    Note: The sorts are always done into ascending order, but by specifying
    the variables in reverse order, you can effectively sort in descending
    order. For more information, please refer to my 2013 SAS Paper:

    Horizontal Data Sorting and Insightful Reporting: A Useful SAS® Technique

    https://support.sas.com/resources/papers/proceedings13/376-2013.pdf

    • This discussion was modified 7 months, 1 week ago by  Datura.

Log in to reply.

Original Post
0 of 0 posts June 2018
Now