<?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 why colon operator with a prefix does not work to reorder variables? in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/why-colon-operator-with-a-prefix-does-not-work-to-reorder/m-p/615487#M18767</link>
    <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I try to use code like this&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data test;&lt;/P&gt;&lt;P&gt;&amp;nbsp; retain ID ACO_: ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set datasetName;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;to put all variables beginning with ACO_ after variable ID. But it does not work. Could anyone give me a clue? Thanks.&lt;/P&gt;&lt;P&gt;Fei&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 06 Jan 2020 22:07:11 GMT</pubDate>
    <dc:creator>hanfei28</dc:creator>
    <dc:date>2020-01-06T22:07:11Z</dc:date>
    <item>
      <title>why colon operator with a prefix does not work to reorder variables?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/why-colon-operator-with-a-prefix-does-not-work-to-reorder/m-p/615487#M18767</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I try to use code like this&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data test;&lt;/P&gt;&lt;P&gt;&amp;nbsp; retain ID ACO_: ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set datasetName;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;to put all variables beginning with ACO_ after variable ID. But it does not work. Could anyone give me a clue? Thanks.&lt;/P&gt;&lt;P&gt;Fei&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jan 2020 22:07:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/why-colon-operator-with-a-prefix-does-not-work-to-reorder/m-p/615487#M18767</guid>
      <dc:creator>hanfei28</dc:creator>
      <dc:date>2020-01-06T22:07:11Z</dc:date>
    </item>
    <item>
      <title>Re: why colon operator with a prefix does not work to reorder variables?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/why-colon-operator-with-a-prefix-does-not-work-to-reorder/m-p/615490#M18769</link>
      <description>&lt;P&gt;For the colon suffix to match any variables they have to already be known to the data step compiler.&amp;nbsp; But if they are already known then their position is already set. So you cannot use that syntax to change their order.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that your test will only change the position of ID since when the RETAIN statement is compiled there are NO variables defined yet.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To see this change the RETAIN statement to a PUT statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  put 'BEFORE SET: ' (ID ACO_: ) (=);
  set datasetName (obs=2);
  put 'AFTER SET: ' (ID ACO_: ) (=);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jan 2020 22:19:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/why-colon-operator-with-a-prefix-does-not-work-to-reorder/m-p/615490#M18769</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-01-06T22:19:25Z</dc:date>
    </item>
    <item>
      <title>Re: why colon operator with a prefix does not work to reorder variables?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/why-colon-operator-with-a-prefix-does-not-work-to-reorder/m-p/615493#M18771</link>
      <description>&lt;P&gt;Could you please show a sample of the data you are reading, and the results that shows that ID is not to the left of the ACO_ variables?&amp;nbsp; Help us help you.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jan 2020 22:16:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/why-colon-operator-with-a-prefix-does-not-work-to-reorder/m-p/615493#M18771</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-01-06T22:16:51Z</dc:date>
    </item>
    <item>
      <title>Re: why colon operator with a prefix does not work to reorder variables?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/why-colon-operator-with-a-prefix-does-not-work-to-reorder/m-p/615494#M18772</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;For the colon suffix to match any variables they have to already be known to the data step compiler.&amp;nbsp; But if they are already known then their position is already set. So you cannot use that syntax to change their order.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I don't think so.&amp;nbsp; The order in data set HAVE below shows ID to the right of ACO_ variables.&amp;nbsp; But using the retain statement in the DATA TEST step re-orders them&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input ACO_1-ACO_3 ID;
  put (_all_) (=);
datalines;
11 111 1111  1
run;

data test;
  retain ID ACO_: ;
  set have;
  put (_all_) (=);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;generates this log:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;142  data have;
143    input ACO_1-ACO_3 ID;
144    put (_all_) (=);
145  datalines;

ACO_1=11 ACO_2=111 ACO_3=1111 ID=1
NOTE: The data set WORK.HAVE has 1 observations and 4 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds


147  run;
148
149  data test;
150    retain ID ACO_: ;
151    set have;
152    put (_all_) (=);
153  run;

ID=1 ACO_1=11 ACO_2=111 ACO_3=1111
NOTE: There were 1 observations read from the data set WORK.HAVE.
NOTE: The data set WORK.TEST has 1 observations and 4 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jan 2020 22:22:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/why-colon-operator-with-a-prefix-does-not-work-to-reorder/m-p/615494#M18772</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-01-06T22:22:08Z</dc:date>
    </item>
    <item>
      <title>Re: why colon operator with a prefix does not work to reorder variables?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/why-colon-operator-with-a-prefix-does-not-work-to-reorder/m-p/615509#M18773</link>
      <description>&lt;P&gt;All you did was move ID to the front since it was the only variable listed in your RETAIN statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Define something before the ACO variables and you will see that they do not "move".&lt;/P&gt;
&lt;PRE&gt;13    data have;
14      input XX ACO_1-ACO_3 ID;
15      put (_all_) (=);
16    datalines;

XX=5 ACO_1=11 ACO_2=111 ACO_3=1111 ID=1
NOTE: The data set WORK.HAVE has 1 observations and 5 variables.
NOTE: DATA statement used (Total process time):
      real time           0.02 seconds
      cpu time            0.00 seconds


18    ;
19
20    data test;
21      retain ID ACO_: ;
22      set have;
23      put (_all_) (=);
24    run;

ID=1 XX=5 ACO_1=11 ACO_2=111 ACO_3=1111
NOTE: There were 1 observations read from the data set WORK.HAVE.
NOTE: The data set WORK.TEST has 1 observations and 5 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;s&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jan 2020 00:14:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/why-colon-operator-with-a-prefix-does-not-work-to-reorder/m-p/615509#M18773</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-01-07T00:14:55Z</dc:date>
    </item>
    <item>
      <title>Re: why colon operator with a prefix does not work to reorder variables?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/why-colon-operator-with-a-prefix-does-not-work-to-reorder/m-p/615520#M18774</link>
      <description>&lt;P&gt;Whenever I need to reorder columns in a specific order, I use dictionary.columns. See example here:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	input aco_1 aco_3 aco_2;
	datalines;
1 3 2
;
run;

data desired_output;
	input aco_1 aco_2 aco_3;
	datalines;
1 2 3
;
run;

data idea1;
	retain aco_:;
	set have;
run;

/*Idea1 does not work, as you have experienced*/
proc compare 
	base=sashelp.vcolumn(where=(libname='WORK' and memname='DESIRED_OUTPUT'))
	compare=sashelp.vcolumn(where=(libname='WORK' and memname='IDEA1'))
;
run;

/*Get ACO varnames into macro var 'aco_vars' (which is ordered numerically)*/
proc sql noprint;
	select name into :aco_vars separated by " "
		from dictionary.columns 
			where 
				upcase(libname)='WORK' and 
				upcase(memname)='HAVE' and
				upcase(name) like 'ACO%'
			order by name
	;
quit;

data idea2;
	retain &amp;amp;aco_vars;
	set have;
run;

/*Idea2 works*/
proc compare
	base=sashelp.vcolumn(where=(libname='WORK' and memname='DESIRED_OUTPUT'))
	compare=sashelp.vcolumn(where=(libname='WORK' and memname='IDEA2'))
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Jan 2020 01:17:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/why-colon-operator-with-a-prefix-does-not-work-to-reorder/m-p/615520#M18774</guid>
      <dc:creator>unison</dc:creator>
      <dc:date>2020-01-07T01:17:57Z</dc:date>
    </item>
    <item>
      <title>Re: why colon operator with a prefix does not work to reorder variables?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/why-colon-operator-with-a-prefix-does-not-work-to-reorder/m-p/615540#M18775</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;All you did was move ID to the front since it was the only variable listed in your RETAIN statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Define something before the ACO variables and you will see that they do not "move".&lt;/P&gt;
&lt;PRE&gt;13    data have;
14      input XX ACO_1-ACO_3 ID;
15      put (_all_) (=);
16    datalines;

XX=5 ACO_1=11 ACO_2=111 ACO_3=1111 ID=1
NOTE: The data set WORK.HAVE has 1 observations and 5 variables.
NOTE: DATA statement used (Total process time):
      real time           0.02 seconds
      cpu time            0.00 seconds


18    ;
19
20    data test;
21      retain ID ACO_: ;
22      set have;
23      put (_all_) (=);
24    run;

ID=1 XX=5 ACO_1=11 ACO_2=111 ACO_3=1111
NOTE: There were 1 observations read from the data set WORK.HAVE.
NOTE: The data set WORK.TEST has 1 observations and 5 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt; &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jan 2020 04:35:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/why-colon-operator-with-a-prefix-does-not-work-to-reorder/m-p/615540#M18775</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-01-07T04:35:21Z</dc:date>
    </item>
  </channel>
</rss>

