<?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: Better way??  (PROC FORMAT with PROC SQL) in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Better-way-PROC-FORMAT-with-PROC-SQL/m-p/63438#M18037</link>
    <description>You can achieve that result of a VALUE statement option and two OPTIONS in PROC SUMMARY.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
proc format;&lt;BR /&gt;
   value Cost(&lt;I&gt;&lt;B&gt;notsorted&lt;/B&gt;&lt;/I&gt;)&lt;BR /&gt;
      0          = '0'&lt;BR /&gt;
      1-4500     = '1-45,00'&lt;BR /&gt;
      4500-6000  = '4,500-6,000'&lt;BR /&gt;
      6000-10000 = '6,000-10,000'&lt;BR /&gt;
      10000-11000 = '10,000-11,000';&lt;BR /&gt;
      ;&lt;BR /&gt;
   run;&lt;BR /&gt;
&lt;BR /&gt;
proc plan seed=1169604082;&lt;BR /&gt;
   factors r=100 ordered cost = 1 of 11000 / noprint;&lt;BR /&gt;
   output out=cost;&lt;BR /&gt;
   Run;&lt;BR /&gt;
proc summary data=cost nway;&lt;BR /&gt;
   class cost / &lt;I&gt;&lt;B&gt;order=data preloadfmt&lt;/B&gt;&lt;/I&gt;;&lt;BR /&gt;
   format cost cost.;&lt;BR /&gt;
   output out=test;&lt;BR /&gt;
   run;&lt;BR /&gt;
proc print;&lt;BR /&gt;
   run;[/pre]</description>
    <pubDate>Thu, 12 Aug 2010 21:17:30 GMT</pubDate>
    <dc:creator>data_null__</dc:creator>
    <dc:date>2010-08-12T21:17:30Z</dc:date>
    <item>
      <title>Better way??  (PROC FORMAT with PROC SQL)</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Better-way-PROC-FORMAT-with-PROC-SQL/m-p/63436#M18035</link>
      <description>Hey guys,&lt;BR /&gt;
&lt;BR /&gt;
I figured out the following way to get my data to sum and print exactly the way I want it.  However, it is quite inelegant coding and I could use some input on better ways.&lt;BR /&gt;
&lt;BR /&gt;
Basically I'm using PROC SQL with a CASE statement to summarize my data in a particular way, and then using PROC FORMAT to make sure the data groupings are ordered properly.  As I say, the following code works, but it seems pretty clunky.&lt;BR /&gt;
&lt;BR /&gt;
proc format;&lt;BR /&gt;
value $Cost '0' = 'a'&lt;BR /&gt;
'1 - 4,500' = 'b'&lt;BR /&gt;
'4,501 - 6,000' = 'c'&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
SELECT CASE&lt;BR /&gt;
WHEN missing(ORIG_COST) THEN '.'&lt;BR /&gt;
WHEN ORIG_COST = 0 THEN '0'&lt;BR /&gt;
WHEN ORIG_COST BETWEEN 1 AND 4500 THEN '1 - 4,500'&lt;BR /&gt;
WHEN ORIG_COST BETWEEN 4501 AND 6000 THEN '4,501 - 6,000'&lt;BR /&gt;
END AS Cost,&lt;BR /&gt;
Count(*)&lt;BR /&gt;
FROM CL.Cleaned_cauto_2007&lt;BR /&gt;
GROUP BY Cost ORDER BY put(Cost, $Cost.);&lt;BR /&gt;
quit;</description>
      <pubDate>Thu, 12 Aug 2010 19:48:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Better-way-PROC-FORMAT-with-PROC-SQL/m-p/63436#M18035</guid>
      <dc:creator>GVeers</dc:creator>
      <dc:date>2010-08-12T19:48:11Z</dc:date>
    </item>
    <item>
      <title>Re: Better way??  (PROC FORMAT with PROC SQL)</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Better-way-PROC-FORMAT-with-PROC-SQL/m-p/63437#M18036</link>
      <description>Oh, and I should also note this is just a sample.  The reason I need the PROC FORMAT is because there are a lot more ranges in my real data and I end up getting ugly results like '10,001 - 25,000' showing up before '6,001 - 10,000' (for example).</description>
      <pubDate>Thu, 12 Aug 2010 19:50:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Better-way-PROC-FORMAT-with-PROC-SQL/m-p/63437#M18036</guid>
      <dc:creator>GVeers</dc:creator>
      <dc:date>2010-08-12T19:50:19Z</dc:date>
    </item>
    <item>
      <title>Re: Better way??  (PROC FORMAT with PROC SQL)</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Better-way-PROC-FORMAT-with-PROC-SQL/m-p/63438#M18037</link>
      <description>You can achieve that result of a VALUE statement option and two OPTIONS in PROC SUMMARY.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
proc format;&lt;BR /&gt;
   value Cost(&lt;I&gt;&lt;B&gt;notsorted&lt;/B&gt;&lt;/I&gt;)&lt;BR /&gt;
      0          = '0'&lt;BR /&gt;
      1-4500     = '1-45,00'&lt;BR /&gt;
      4500-6000  = '4,500-6,000'&lt;BR /&gt;
      6000-10000 = '6,000-10,000'&lt;BR /&gt;
      10000-11000 = '10,000-11,000';&lt;BR /&gt;
      ;&lt;BR /&gt;
   run;&lt;BR /&gt;
&lt;BR /&gt;
proc plan seed=1169604082;&lt;BR /&gt;
   factors r=100 ordered cost = 1 of 11000 / noprint;&lt;BR /&gt;
   output out=cost;&lt;BR /&gt;
   Run;&lt;BR /&gt;
proc summary data=cost nway;&lt;BR /&gt;
   class cost / &lt;I&gt;&lt;B&gt;order=data preloadfmt&lt;/B&gt;&lt;/I&gt;;&lt;BR /&gt;
   format cost cost.;&lt;BR /&gt;
   output out=test;&lt;BR /&gt;
   run;&lt;BR /&gt;
proc print;&lt;BR /&gt;
   run;[/pre]</description>
      <pubDate>Thu, 12 Aug 2010 21:17:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Better-way-PROC-FORMAT-with-PROC-SQL/m-p/63438#M18037</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2010-08-12T21:17:30Z</dc:date>
    </item>
    <item>
      <title>Re: Better way??  (PROC FORMAT with PROC SQL)</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Better-way-PROC-FORMAT-with-PROC-SQL/m-p/63439#M18038</link>
      <description>Thanks, dall_null.  I appreciate the response, particularly since I did not know about the power of PROC SUMMARY.&lt;BR /&gt;
&lt;BR /&gt;
Still, I think this doesn't quite help me.  My data set has a number of variables that I need to seperate into ranges, output with a specific character field, and print in numeric order.  I think the way you describe will require sorting the data for each variable I need to output, which seems about as efficient as my approach.&lt;BR /&gt;
&lt;BR /&gt;
I guess what would be ideal is if there was some procedure that could assign a label to a variable (like PROC FORMAT) but also assign a value for sorting purposes.  If anyone knows of such a thing, I'd love to hear it, but I can stick to what I have as well.&lt;BR /&gt;
&lt;BR /&gt;
Thanks!</description>
      <pubDate>Fri, 13 Aug 2010 15:00:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Better-way-PROC-FORMAT-with-PROC-SQL/m-p/63439#M18038</guid>
      <dc:creator>GVeers</dc:creator>
      <dc:date>2010-08-13T15:00:13Z</dc:date>
    </item>
    <item>
      <title>Re: Better way??  (PROC FORMAT with PROC SQL)</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Better-way-PROC-FORMAT-with-PROC-SQL/m-p/63440#M18039</link>
      <description>How about an option to create an index variable associated with the levels of the CLASS variable(s).&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
dm 'clear log; clear output;';&lt;BR /&gt;
proc format;&lt;BR /&gt;
   value Cost(notsorted)&lt;BR /&gt;
      0          = '0'&lt;BR /&gt;
      1-4500     = '1-45,00'&lt;BR /&gt;
      4500-6000  = '4,500-6,000'&lt;BR /&gt;
      6000-10000 = '6,000-10,000'&lt;BR /&gt;
      10000-11000 = '10,000-11,000';&lt;BR /&gt;
      ;&lt;BR /&gt;
   value xCost(notsorted)&lt;BR /&gt;
      0          = '0'&lt;BR /&gt;
      3500-7000  = '3,500-7,000' /*for example*/&lt;BR /&gt;
      1-3500     = '1-3,400'&lt;BR /&gt;
      7000-10000 = '6,000-10,000'&lt;BR /&gt;
      10000-11000 = '10,000-11,000';&lt;BR /&gt;
      ;&lt;BR /&gt;
&lt;BR /&gt;
   run;&lt;BR /&gt;
&lt;BR /&gt;
proc plan seed=1169604082;&lt;BR /&gt;
   factors r=100 ordered cost = 1 of 11000 / noprint;&lt;BR /&gt;
   output out=cost;&lt;BR /&gt;
   Run;&lt;BR /&gt;
data cost;&lt;BR /&gt;
   set cost;&lt;BR /&gt;
   xcost = cost;&lt;BR /&gt;
   run;&lt;BR /&gt;
proc summary data=cost;&lt;BR /&gt;
   class cost xcost/ order=data preloadfmt;&lt;BR /&gt;
   ways 1;&lt;BR /&gt;
   format cost cost. xcost xcost.;&lt;BR /&gt;
   output out=test / &lt;I&gt;&lt;B&gt;levels&lt;/B&gt;&lt;/I&gt;;&lt;BR /&gt;
   run;&lt;BR /&gt;
proc print;&lt;BR /&gt;
   run;&lt;BR /&gt;
proc print;&lt;BR /&gt;
   format _all_;&lt;BR /&gt;
   run;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Fri, 13 Aug 2010 15:46:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Better-way-PROC-FORMAT-with-PROC-SQL/m-p/63440#M18039</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2010-08-13T15:46:17Z</dc:date>
    </item>
    <item>
      <title>Re: Better way??  (PROC FORMAT with PROC SQL)</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Better-way-PROC-FORMAT-with-PROC-SQL/m-p/63441#M18040</link>
      <description>Thanks again, data_null.  That could do it.</description>
      <pubDate>Fri, 13 Aug 2010 20:46:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Better-way-PROC-FORMAT-with-PROC-SQL/m-p/63441#M18040</guid>
      <dc:creator>GVeers</dc:creator>
      <dc:date>2010-08-13T20:46:02Z</dc:date>
    </item>
  </channel>
</rss>

