<?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 prevent sort in PROC CONTENTS? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-prevent-sort-in-PROC-CONTENTS/m-p/426532#M105097</link>
    <description>&lt;P&gt;I don't think you can prevent it, but you can correct it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sort the out= data set:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;by varnum;&lt;/P&gt;</description>
    <pubDate>Wed, 10 Jan 2018 16:27:30 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2018-01-10T16:27:30Z</dc:date>
    <item>
      <title>How to prevent sort in PROC CONTENTS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-prevent-sort-in-PROC-CONTENTS/m-p/426526#M105095</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is it possible to prevent PROC CONTENTS from sorting the OUT= output? I need to process some column names in a data set, but I need them to remain in their original order.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've read through numerous documents for different versions of SAS, but I'm not seeing this option. Just want to make sure I haven't overlooked it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jan 2018 16:18:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-prevent-sort-in-PROC-CONTENTS/m-p/426526#M105095</guid>
      <dc:creator>beacon</dc:creator>
      <dc:date>2018-01-10T16:18:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to prevent sort in PROC CONTENTS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-prevent-sort-in-PROC-CONTENTS/m-p/426532#M105097</link>
      <description>&lt;P&gt;I don't think you can prevent it, but you can correct it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sort the out= data set:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;by varnum;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jan 2018 16:27:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-prevent-sort-in-PROC-CONTENTS/m-p/426532#M105097</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-01-10T16:27:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to prevent sort in PROC CONTENTS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-prevent-sort-in-PROC-CONTENTS/m-p/426533#M105098</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc contents data=sashelp.class out=test noprint;
run;

proc sort data=test;
	by Varnum;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 10 Jan 2018 16:28:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-prevent-sort-in-PROC-CONTENTS/m-p/426533#M105098</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2018-01-10T16:28:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to prevent sort in PROC CONTENTS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-prevent-sort-in-PROC-CONTENTS/m-p/426539#M105101</link>
      <description>&lt;P&gt;You do not need to use proc contents.&amp;nbsp; You can access the metadata directly by using either:&lt;/P&gt;
&lt;P&gt;sashelp.vtable and sashelp.vcolumn&lt;/P&gt;
&lt;P&gt;Or in sql by the dictionary.tables/columns.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jan 2018 16:44:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-prevent-sort-in-PROC-CONTENTS/m-p/426539#M105101</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-01-10T16:44:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to prevent sort in PROC CONTENTS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-prevent-sort-in-PROC-CONTENTS/m-p/426543#M105103</link>
      <description>&lt;P&gt;You may want to explore the&amp;nbsp;DICTIONARY tables available with Proc SQL, see example below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It gives you easy access&amp;nbsp;to the column and table information using SQL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See also&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://go.documentation.sas.com/?docsetId=sqlproc&amp;amp;docsetTarget=n02s19q65mw08gn140bwfdh7spx7.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank"&gt;http://go.documentation.sas.com/?docsetId=sqlproc&amp;amp;docsetTarget=n02s19q65mw08gn140bwfdh7spx7.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  create table myvars as
  select
    *
  from
    dictionary.columns
  where
    libname = "SASHELP"
    and memname = "CARS"
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 10 Jan 2018 16:53:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-prevent-sort-in-PROC-CONTENTS/m-p/426543#M105103</guid>
      <dc:creator>BrunoMueller</dc:creator>
      <dc:date>2018-01-10T16:53:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to prevent sort in PROC CONTENTS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-prevent-sort-in-PROC-CONTENTS/m-p/426544#M105104</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/107180"&gt;@beacon&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is it possible to prevent PROC CONTENTS from sorting the OUT= output? I need to process some column names in a data set, but I need them to remain in their original order.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've read through numerous documents for different versions of SAS, but I'm not seeing this option. Just want to make sure I haven't overlooked it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Please provide an example, or at least a description of what you are doing, that variable order from a proc contents data set is critical.&lt;/P&gt;
&lt;P&gt;I am having a hard time coming up with an example..&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jan 2018 16:53:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-prevent-sort-in-PROC-CONTENTS/m-p/426544#M105104</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-01-10T16:53:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to prevent sort in PROC CONTENTS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-prevent-sort-in-PROC-CONTENTS/m-p/426550#M105107</link>
      <description>&lt;P&gt;So, upon further testing, using some of the examples provided above, it appears as though the issue is actually with a subsequent PROC SQL where I'm trying to return DISTINCT records.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;/* There are additional columns that are not listed that are in the data set 'x' */
DATA x;
    INPUT C_UV $ C_WX $ C_YZ $ C_ST $ C_QR $ B_UV $ B_WX $ B_YZ $ B_ST $ B_QR $ E_UV $ E_WX $ E_YZ $ E_ST $ E_QR $ D_UV $ D_WX $ D_YZ $ D_ST $ D_QR $ A_UV $ A_WX $ A_YZ $ A_ST $ A_QR $;
    DATALINES;
    ...

PROC CONTENTS DATA=x OUT=y VARNUM;
RUN;

PROC SQL;
    /* Get just the portion of the code after the underscore and sort by original order */
    CREATE TABLE a AS
        SELECT
            PRXCHANGE('s/^(\D{1})_(\w+)/$2/', -1, NAME) AS CODE
        FROM
            y
        WHERE
            PRXMATCH('/^\D{1}_/', NAME)
        ORDER BY
            VARNUM
        ;

    /* Get the distinct code after sort */
    CREATE TABLE b AS
        SELECT DISTINCT
            CODE
        FROM
            a
        ;
QUIT;

PROC PRINT DATA=b;
RUN;

/* Desired Output
CODE
-----------
UV
WX
YZ
ST
QR
*/

/* Actual Output

CODE
-----------
QR
ST
UV
WX
YZ
*/&lt;/PRE&gt;&lt;P&gt;I tried to pin this down and thought it was because of PROC CONTENTS, but that's because I mistakenly thought that the DISTINCT clause in PROC SQL was a standardized implementation that didn't return values in sorted order, as is apparently the case.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jan 2018 17:18:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-prevent-sort-in-PROC-CONTENTS/m-p/426550#M105107</guid>
      <dc:creator>beacon</dc:creator>
      <dc:date>2018-01-10T17:18:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to prevent sort in PROC CONTENTS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-prevent-sort-in-PROC-CONTENTS/m-p/426553#M105108</link>
      <description>&lt;P&gt;if you keep VARNUM in table a you can still use it for order by in the table b creation without including in the output.&lt;/P&gt;
&lt;P&gt;OR if you don't really need table A&lt;/P&gt;
&lt;PRE&gt;PROC SQL;
    /* Get just the portion of the code after the underscore and sort by original order */
    CREATE TABLE b  AS
        SELECT
           distinct PRXCHANGE('s/^(\D{1})_(\w+)/$2/', -1, NAME) AS CODE
        FROM
            y
        WHERE
            PRXMATCH('/^\D{1}_/', NAME)
        ORDER BY
            VARNUM
        ;
quit;&lt;/PRE&gt;</description>
      <pubDate>Wed, 10 Jan 2018 17:24:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-prevent-sort-in-PROC-CONTENTS/m-p/426553#M105108</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-01-10T17:24:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to prevent sort in PROC CONTENTS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-prevent-sort-in-PROC-CONTENTS/m-p/426559#M105109</link>
      <description>&lt;P&gt;I tried that, but I get the following warning:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;WARNING: The query as specified involves ordering by an item that doesn't appear in its SELECT
         clause. Since you are ordering the output of a SELECT DISTINCT it may appear that some
         duplicates have not been eliminated.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Despite the warning, the output is incorrect. Here is the desired output and the actual output (when I try to ORDER BY with DISTINCT):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;/* Desired Output
CODE
-----------
UV
WX
YZ
ST
QR
*/

/* Actual Output

CODE
-----------
UV
WX
YZ
ST
QR
UV
WX
YZ
ST
QR
UV
WX
YZ
ST
QR
UV
WX
YZ
ST
QR
UV
WX
YZ
ST
QR
*/&lt;/PRE&gt;&lt;P&gt;I tried to use an inline view to sort and limit the values returned to the main query, but inline views apparently don't allow the ORDER BY clause.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jan 2018 17:34:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-prevent-sort-in-PROC-CONTENTS/m-p/426559#M105109</guid>
      <dc:creator>beacon</dc:creator>
      <dc:date>2018-01-10T17:34:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to prevent sort in PROC CONTENTS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-prevent-sort-in-PROC-CONTENTS/m-p/426574#M105112</link>
      <description>&lt;P&gt;That warning message is pretty explicit.&amp;nbsp; You should be able to fix the situation&amp;nbsp;by changing one line of the program from:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SELECT&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instead, make it:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SELECT VARNUM,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jan 2018 18:21:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-prevent-sort-in-PROC-CONTENTS/m-p/426574#M105112</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-01-10T18:21:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to prevent sort in PROC CONTENTS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-prevent-sort-in-PROC-CONTENTS/m-p/426604#M105118</link>
      <description>&lt;P&gt;If I use the code suggested by &lt;STRONG&gt;ballardw&lt;/STRONG&gt;, which I had tried, it looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
    /* Get just the portion of the code after the underscore and sort by original order */
    CREATE TABLE b  AS
        SELECT DISTINCT
            PRXCHANGE('s/^(\D{1})_(\w+)/$2/', -1, NAME) AS CODE
        FROM
            y
        WHERE
            PRXMATCH('/^\D{1}_/', NAME)
        ORDER BY
            VARNUM
        ;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;If you're suggesting that I change it to the following, it &lt;U&gt;will&lt;/U&gt; remove the warning, but it won't produce the desired output:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
    /* Get just the portion of the code after the underscore and sort by original order */
    CREATE TABLE b  AS
        SELECT DISTINCT
            PRXCHANGE('s/^(\D{1})_(\w+)/$2/', -1, NAME) AS CODE,
            VARNUM    /* Added VARNUM, per Astounding's suggestion */
        FROM
            y
        WHERE
            PRXMATCH('/^\D{1}_/', NAME)
        ORDER BY
            VARNUM
        ;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;If you were suggesting that I use the code above, but remove DISTINCT, that also does not produce the desired output. The above code and the code above without DISTINCT both produce the following results:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;/* Actual Output

CODE         VARNUM
-----------  -----------
UV           73
WX           74
YZ           75
ST           76
QR           77
UV           78
WX           79
YZ           80
ST           81
QR           82
UV           83
WX           84
YZ           85
ST           86
QR           87
UV           88
WX           89
YZ           90
ST           91
QR           92
UV           93
WX           94
YZ           95
ST           96
QR           97
*/

/* Desired Output
CODE
-----------
UV
WX
YZ
ST
QR
*/&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jan 2018 19:05:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-prevent-sort-in-PROC-CONTENTS/m-p/426604#M105118</guid>
      <dc:creator>beacon</dc:creator>
      <dc:date>2018-01-10T19:05:44Z</dc:date>
    </item>
  </channel>
</rss>

