<?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: Why while extracting column names is changing sequence? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Why-while-extracting-column-names-is-changing-sequence/m-p/530580#M145122</link>
    <description>&lt;P&gt;Tried following-&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc contents data=new order=varnum out=new1(keep=Name);
run;
proc print data=new1;run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Not getting sequence in original form in data(new1).&lt;/P&gt;</description>
    <pubDate>Mon, 28 Jan 2019 10:56:58 GMT</pubDate>
    <dc:creator>Kaushik1</dc:creator>
    <dc:date>2019-01-28T10:56:58Z</dc:date>
    <item>
      <title>Why while extracting column names is changing sequence?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-while-extracting-column-names-is-changing-sequence/m-p/530577#M145120</link>
      <description>&lt;P&gt;I am trying below code-&lt;/P&gt;&lt;P&gt;Columns in data(new) are in the following format-&amp;nbsp;&lt;CODE class=" language-sas"&gt;A, B, E, F, C, D.&lt;/CODE&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data new;
input A B E F C D;
datalines;
1 2 3 4 6 5
2 4 6 7 8 6
1 3 4 5 3 7
4 6 2 1 3 7
1 4 9 7 2 3
;&lt;/CODE&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;but while getting contents the sequence is changing.&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;i.e. data(new1) is consisting columns of of data(new) in the following format- A, B, C, D, E, F.&amp;nbsp;&lt;/CODE&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc print data=new;run;
proc contents data=new out=new1(keep=NAME) noprint;
run;
proc print data=new1;run;&lt;/CODE&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;Question- Why it is changing the sequence?&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;If I required data(new1) in the same format then what should I do?&lt;/CODE&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Jan 2019 10:48:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-while-extracting-column-names-is-changing-sequence/m-p/530577#M145120</guid>
      <dc:creator>Kaushik1</dc:creator>
      <dc:date>2019-01-28T10:48:57Z</dc:date>
    </item>
    <item>
      <title>Re: Why while extracting column names is changing sequence?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-while-extracting-column-names-is-changing-sequence/m-p/530579#M145121</link>
      <description>&lt;P&gt;If you look at sashelp.vcolumn - which is basically what you are printing, you will see the column name, label, length etc. as metadata.&amp;nbsp; One of the columns in there is varnum.&amp;nbsp; This defines the actual order, but the data is sorted alphabetically by default.&amp;nbsp; So you can just sort by using the orderby option:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/proc/65145/HTML/default/viewer.htm#p0b3vc5qd4rg06n1g6ds45cgbke2.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/proc/65145/HTML/default/viewer.htm#p0b3vc5qd4rg06n1g6ds45cgbke2.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Jan 2019 10:43:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-while-extracting-column-names-is-changing-sequence/m-p/530579#M145121</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2019-01-28T10:43:49Z</dc:date>
    </item>
    <item>
      <title>Re: Why while extracting column names is changing sequence?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-while-extracting-column-names-is-changing-sequence/m-p/530580#M145122</link>
      <description>&lt;P&gt;Tried following-&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc contents data=new order=varnum out=new1(keep=Name);
run;
proc print data=new1;run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Not getting sequence in original form in data(new1).&lt;/P&gt;</description>
      <pubDate>Mon, 28 Jan 2019 10:56:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-while-extracting-column-names-is-changing-sequence/m-p/530580#M145122</guid>
      <dc:creator>Kaushik1</dc:creator>
      <dc:date>2019-01-28T10:56:58Z</dc:date>
    </item>
    <item>
      <title>Re: Why while extracting column names is changing sequence?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-while-extracting-column-names-is-changing-sequence/m-p/530588#M145127</link>
      <description>&lt;P&gt;Please avoid bad coding practices such as missing run off and putting run on same line, make code as easy to read as possible.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data new;
  input a b e f c d;
datalines;
1 2 3 4 6 5
2 4 6 7 8 6
1 3 4 5 3 7
4 6 2 1 3 7
1 4 9 7 2 3
;
run;

proc contents data=new order=varnum out=new1(keep=Name);
run;

proc print data=new1;
run;&lt;/PRE&gt;
&lt;P&gt;Results in:&lt;/P&gt;
&lt;PRE&gt;...


                                    Variables in Creation Order
 
                                   #    Variable    Type    Len

                                   1    a           Num       8
                                   2    b           Num       8
                                   3    e           Num       8
                                   4    f           Num       8
                                   5    c           Num       8
                                   6    d           Num       8
                                          The SAS System        11:10 Monday, January 28, 2019   2

                                           Obs    NAME

                                            1      a  
                                            2      b  
                                            3      c  
                                            4      d  
                                            5      e  
                                            6      f  
&lt;/PRE&gt;
&lt;P&gt;In section 1 you will see the variables ordered as per the creation order.&lt;/P&gt;
&lt;P&gt;If you want the print to display in that order, then you need to sort the dataset:&lt;/P&gt;
&lt;PRE&gt;data new;
  input a b e f c d;
datalines;
1 2 3 4 6 5
2 4 6 7 8 6
1 3 4 5 3 7
4 6 2 1 3 7
1 4 9 7 2 3
;
run;

proc contents data=new out=new1 (keep=varnum name) noprint;
run;

proc sort data=new1;
  by varnum;
run;

proc print data=new1;
  var name;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And you can ditch the proc compare totally and just report out the metadata like:&lt;/P&gt;
&lt;PRE&gt;data new;
  input a b e f c d;
datalines;
1 2 3 4 6 5
2 4 6 7 8 6
1 3 4 5 3 7
4 6 2 1 3 7
1 4 9 7 2 3
;
run;

proc sort data=sashelp.vcolumn out=new1 (keep=name);
  by varnum;
  where libname="WORK" and memname="NEW";
run;

proc print data=new1;
  var name;
run;&lt;/PRE&gt;
&lt;P&gt;Thats generally more effective than proc contents then report.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Jan 2019 11:21:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-while-extracting-column-names-is-changing-sequence/m-p/530588#M145127</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2019-01-28T11:21:12Z</dc:date>
    </item>
  </channel>
</rss>

