<?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 Question about the order of memname  and indsname in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Question-about-the-order-of-memname-and-indsname/m-p/238641#M308765</link>
    <description>&lt;P&gt;In the following code1, the memname is sorted by ascending; but in the log window, the result of %put statement shows that the order of Y_names is like Y1 Y100 Y101...Y2, Y201...Y3...Y99&lt;/P&gt;&lt;P&gt;Does this mean the ascending order in code 1 is different from traditional ascending order? I thought that traditional ascending order should be like Y1 Y2 Y3....Y99 Y100 Y101...Y201;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In code 2, indsname order is also like the order of X&lt;SPAN&gt;1 X100 X101...X2, X201...X3...X99. How to make it in order&amp;nbsp;X1 X2 X3....X99 X100 X101...X201 ?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*code 1;
proc sql print;
select distinct memname into :Y_names 
separated by ' ' 
from dictionary.tables 
where libname='WORK' and upcase(memname) like 'Y%'
order by memname asc;
%let y_numobs=&amp;amp;sqlobs; 
quit;
%put &amp;amp;Y_names;
&lt;BR /&gt;/* The order is important because I will use&amp;nbsp;&lt;BR /&gt;%do i = 1 %to &amp;amp;y_numobs;&lt;BR /&gt;%let yy=%scan(&amp;amp;Y_names, &amp;amp;i, ' ');*/&lt;BR /&gt;
*code 2;
data alloutput;
   set &amp;amp;Y_names open=defer indsname=indsname;
   dataname = indsname;
   if lag(indsname) ne indsname then datacheck + 1; 
run; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 10 Dec 2015 09:17:41 GMT</pubDate>
    <dc:creator>Jonate_H</dc:creator>
    <dc:date>2015-12-10T09:17:41Z</dc:date>
    <item>
      <title>Question about the order of memname  and indsname</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-the-order-of-memname-and-indsname/m-p/238641#M308765</link>
      <description>&lt;P&gt;In the following code1, the memname is sorted by ascending; but in the log window, the result of %put statement shows that the order of Y_names is like Y1 Y100 Y101...Y2, Y201...Y3...Y99&lt;/P&gt;&lt;P&gt;Does this mean the ascending order in code 1 is different from traditional ascending order? I thought that traditional ascending order should be like Y1 Y2 Y3....Y99 Y100 Y101...Y201;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In code 2, indsname order is also like the order of X&lt;SPAN&gt;1 X100 X101...X2, X201...X3...X99. How to make it in order&amp;nbsp;X1 X2 X3....X99 X100 X101...X201 ?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*code 1;
proc sql print;
select distinct memname into :Y_names 
separated by ' ' 
from dictionary.tables 
where libname='WORK' and upcase(memname) like 'Y%'
order by memname asc;
%let y_numobs=&amp;amp;sqlobs; 
quit;
%put &amp;amp;Y_names;
&lt;BR /&gt;/* The order is important because I will use&amp;nbsp;&lt;BR /&gt;%do i = 1 %to &amp;amp;y_numobs;&lt;BR /&gt;%let yy=%scan(&amp;amp;Y_names, &amp;amp;i, ' ');*/&lt;BR /&gt;
*code 2;
data alloutput;
   set &amp;amp;Y_names open=defer indsname=indsname;
   dataname = indsname;
   if lag(indsname) ne indsname then datacheck + 1; 
run; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Dec 2015 09:17:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-the-order-of-memname-and-indsname/m-p/238641#M308765</guid>
      <dc:creator>Jonate_H</dc:creator>
      <dc:date>2015-12-10T09:17:41Z</dc:date>
    </item>
    <item>
      <title>Re: Question about the order of memname  and indsname</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-the-order-of-memname-and-indsname/m-p/238645#M308766</link>
      <description>&lt;P&gt;This is due to the fact that Y1, Y100 etc. are character values, not numeric, they are being sorted as text strings. &amp;nbsp;I wouldn't suggest doing what you are trying to do, macro variables and code is not great for processing long lists of variables and the code gets messy. &amp;nbsp;The simplest way of dealing with data of this type is to normalise it, i.e:&lt;/P&gt;
&lt;P&gt;ID &amp;nbsp; &amp;nbsp; YVAL &amp;nbsp; &amp;nbsp; YRESULT&lt;/P&gt;
&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; xyz&lt;/P&gt;
&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; 2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The above structure will make you life and coding far easier. &amp;nbsp;Alternatively there is arrays:&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; set have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; array y{&amp;amp;y_numobs.};&lt;/P&gt;
&lt;P&gt;&amp;nbsp; do i=1 to dim(y{*});&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is just two ways of coding what you are trying to do using simple base SAS code.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Dec 2015 09:35:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-the-order-of-memname-and-indsname/m-p/238645#M308766</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-12-10T09:35:53Z</dc:date>
    </item>
    <item>
      <title>Re: Question about the order of memname  and indsname</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-the-order-of-memname-and-indsname/m-p/238655#M308767</link>
      <description>&lt;P&gt;The PROC SORT option&amp;nbsp;sortseq=linguistic(numeric_collation=on) will order v1 v2 v3 v10 v11 in the "correct" order.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Dec 2015 10:20:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-the-order-of-memname-and-indsname/m-p/238655#M308767</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2015-12-10T10:20:34Z</dc:date>
    </item>
    <item>
      <title>Re: Question about the order of memname  and indsname</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-the-order-of-memname-and-indsname/m-p/238712#M308768</link>
      <description>It sorts alphabetically, because the variable is text.  Use the sort option specified by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10092"&gt;@Data_null_&lt;/a&gt; to set the sort option so that it sorts numerically.</description>
      <pubDate>Thu, 10 Dec 2015 15:51:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-the-order-of-memname-and-indsname/m-p/238712#M308768</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-12-10T15:51:20Z</dc:date>
    </item>
    <item>
      <title>Re: Question about the order of memname  and indsname</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-the-order-of-memname-and-indsname/m-p/238723#M308769</link>
      <description>&lt;P&gt;Thank you all for your kindly help! I have learnt a lot from the community.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Dec 2015 16:26:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-the-order-of-memname-and-indsname/m-p/238723#M308769</guid>
      <dc:creator>Jonate_H</dc:creator>
      <dc:date>2015-12-10T16:26:35Z</dc:date>
    </item>
  </channel>
</rss>

