<?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: Proc SQL order by value not ascii in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Proc-SQL-order-by-value-not-ascii/m-p/633386#M21156</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/311215"&gt;@cactooos&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;I might use the output directly from proc sql so was looking for some kind of workaround like this&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;In general, for all but the simplest problems, PROC SQL is not a good tool for creating tables. I know people use it for that, but its not a good choice, and its not what PROC SQL was designed to do. PROC REPORT has so many more features to help you get the right report, and to obtain the right report with much less coding than would be required in PROC SQL (for all but the simplest problems).&lt;/P&gt;</description>
    <pubDate>Thu, 19 Mar 2020 18:42:41 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2020-03-19T18:42:41Z</dc:date>
    <item>
      <title>Proc SQL order by value not ascii</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Proc-SQL-order-by-value-not-ascii/m-p/633221#M21148</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;Just wondering if there is any better way of having kind of custom group order that the code below. I have format:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format ;
value valband
0 = '0'
0&amp;lt;-30 = '0-30'
30&amp;lt;-90 = '30-90'
90&amp;lt;-215 = '90-215'
215&amp;lt;-430= '215-430'
430-high = 'over 430';
run ;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But when I do group by in proc sql I see the order:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;0
0-30
215-430
30-90 etc.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;obviously I would like to have it ordered by value. I found a solution with additional ranking created by case when, is this the only/easiest way of doing this?&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;order by case when val_bin = '0' then 1
	when val_bin = '0-30' 		then 2
	when val_bin = '30-90' 		then 3
	when val_bin = '90-215' 	then 4
	when val_bin = '215-430' 	then 5
	when val_bin = 'over 430' 	then 6 
end&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 19 Mar 2020 11:36:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Proc-SQL-order-by-value-not-ascii/m-p/633221#M21148</guid>
      <dc:creator>cactooos</dc:creator>
      <dc:date>2020-03-19T11:36:45Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL order by value not ascii</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Proc-SQL-order-by-value-not-ascii/m-p/633223#M21149</link>
      <description>&lt;P&gt;If you are using PROC SQL to create data sets, it really doesn't matter what order the data is in. You can always use PROC TABULATE or PROC REPORT to obtain an output in the order you want. Please make note of this concept: your SAS data set does not have to be in the order you want it when a print or output is desired; the output procedure can do the ordering for you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are using PROC SQL to create a report, then you need a work-around as you have done.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Mar 2020 11:41:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Proc-SQL-order-by-value-not-ascii/m-p/633223#M21149</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-03-19T11:41:15Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL order by value not ascii</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Proc-SQL-order-by-value-not-ascii/m-p/633228#M21150</link>
      <description>&lt;P&gt;Try padding white blanks before format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format ;
value valband
0 = '                0'
0&amp;lt;-30 = '      0-30'
30&amp;lt;-90 = '   30-90'
90&amp;lt;-215 = '  90-215'
215&amp;lt;-430= ' 215-430'
430-high = 'over 430';
run ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 19 Mar 2020 12:03:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Proc-SQL-order-by-value-not-ascii/m-p/633228#M21150</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-03-19T12:03:09Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL order by value not ascii</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Proc-SQL-order-by-value-not-ascii/m-p/633327#M21151</link>
      <description>&lt;P&gt;I think you are missing the step that links the numeric value to your val_bin variable.&amp;nbsp; And it isn't needed.&lt;/P&gt;
&lt;PRE&gt;proc sql;
   create table work.want as
   select value,
         case
            when (value=0)            then 1
            when (  0 lt value le 30) then 2
            when ( 30 lt value le 90) then 3
            when ( 90 lt value le 215)then 4
            when (215 lt value le 430)then 5
            when (430 lt value)       then 6
            else .
         end  as Valband
  from have
  ;
quit;
&lt;/PRE&gt;
&lt;P&gt;Or read the data with an informat at an earlier step.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Mar 2020 15:44:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Proc-SQL-order-by-value-not-ascii/m-p/633327#M21151</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-03-19T15:44:09Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL order by value not ascii</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Proc-SQL-order-by-value-not-ascii/m-p/633383#M21155</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;I might use the output directly from proc sql so was looking for some kind of workaround like this&lt;BR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;I am using two variables: value and value_band with the format valueband. which I created at the beginning, I'm doing some grouping and classifications on the way so the question was stricte about the order of these groups but thank you for your point&lt;/P&gt;</description>
      <pubDate>Thu, 19 Mar 2020 18:36:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Proc-SQL-order-by-value-not-ascii/m-p/633383#M21155</guid>
      <dc:creator>cactooos</dc:creator>
      <dc:date>2020-03-19T18:36:43Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL order by value not ascii</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Proc-SQL-order-by-value-not-ascii/m-p/633386#M21156</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/311215"&gt;@cactooos&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;I might use the output directly from proc sql so was looking for some kind of workaround like this&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;In general, for all but the simplest problems, PROC SQL is not a good tool for creating tables. I know people use it for that, but its not a good choice, and its not what PROC SQL was designed to do. PROC REPORT has so many more features to help you get the right report, and to obtain the right report with much less coding than would be required in PROC SQL (for all but the simplest problems).&lt;/P&gt;</description>
      <pubDate>Thu, 19 Mar 2020 18:42:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Proc-SQL-order-by-value-not-ascii/m-p/633386#M21156</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-03-19T18:42:41Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL order by value not ascii</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Proc-SQL-order-by-value-not-ascii/m-p/633395#M21157</link>
      <description>&lt;P&gt;When you have a format available for a variable then frequently there is no reason needed to create a text version of the variable. The group created by the format will be honored by almost all&amp;nbsp;the SAS reporting, analysis and graphing procedures. I say "almost all" as I don't use every single procedure but the ones I use the formatted value works just fine.&lt;/P&gt;
&lt;P&gt;Here's an example of using two different formats on the same variable to create two similar reports with different groups:&lt;/P&gt;
&lt;PRE&gt;proc format library=work;
value age3grp
10 - 12 = '10-12 Years'
13 - 15 = '13-15 Years'
16 - high= '16+ Years'
;
value age2grp
10 - 13 = '10-13 Years'
13 - high= '13+ Years'
;
run;

proc report data=sashelp.class;
   columns sex age height,(n pctn);
   define sex / group ;
   define age / group format=age3grp.;
   define height/analysis;
run;
proc report data=sashelp.class;
   columns sex age height,(n pctn);
   define sex / group ;
   define age / group format=age2grp.;
   define height/analysis;
run;&lt;/PRE&gt;
&lt;P&gt;You should have the Sashelp.class data set available to run the code.&lt;/P&gt;
&lt;P&gt;Not having to add variables and just apply a different format is a very powerful tool.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Mar 2020 19:10:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Proc-SQL-order-by-value-not-ascii/m-p/633395#M21157</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-03-19T19:10:30Z</dc:date>
    </item>
  </channel>
</rss>

