<?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 How do I format a variable as % and comma10. in same column using proc sql? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-format-a-variable-as-and-comma10-in-same-column-using/m-p/952808#M372353</link>
    <description>&lt;P&gt;Hello all,&lt;/P&gt;
&lt;P&gt;I have a client that INSISTS that EVERYTHING be done in PROC SQL. So I need the following.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have output that has both comma and numeric formatting in the same column. The client wants the results in a dataset (again, don't ask).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The pos positions 1 &amp;amp; 2 need to be comma10. format, and pos 3 needs to be nlpcti10.2&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="208"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="65.0625px"&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;descr&amp;nbsp;&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="79.075px"&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;col 1&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="63.0625px"&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;pos&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="65.0625px"&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;Total&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="79.075px"&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 123,456&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="63.0625px"&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;1&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="65.0625px"&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;Change&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="79.075px"&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 123&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="63.0625px"&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;2&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="65.0625px"&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;% Change&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="79.075px"&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;45%&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="63.0625px"&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;3&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;CAN that be done in PROC SQL? At least I have the flags so only pos = 3 needs the percent format, pos = 1, 2 need the comma10.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried using a CASE WHEN but it doesn't work. If I have to do it in a DATA step, OK, but they won't allow a proc format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have tried it in PROC REPORT but the output dataset doesn't hold the formatting nor the new variable names.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HELP PLEASE! I'M DESPERATE&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;</description>
    <pubDate>Fri, 06 Dec 2024 22:56:48 GMT</pubDate>
    <dc:creator>SASGeek</dc:creator>
    <dc:date>2024-12-06T22:56:48Z</dc:date>
    <item>
      <title>How do I format a variable as % and comma10. in same column using proc sql?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-format-a-variable-as-and-comma10-in-same-column-using/m-p/952808#M372353</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;
&lt;P&gt;I have a client that INSISTS that EVERYTHING be done in PROC SQL. So I need the following.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have output that has both comma and numeric formatting in the same column. The client wants the results in a dataset (again, don't ask).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The pos positions 1 &amp;amp; 2 need to be comma10. format, and pos 3 needs to be nlpcti10.2&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="208"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="65.0625px"&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;descr&amp;nbsp;&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="79.075px"&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;col 1&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="63.0625px"&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;pos&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="65.0625px"&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;Total&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="79.075px"&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 123,456&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="63.0625px"&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;1&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="65.0625px"&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;Change&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="79.075px"&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 123&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="63.0625px"&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;2&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="65.0625px"&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;% Change&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="79.075px"&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;45%&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="63.0625px"&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;3&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;CAN that be done in PROC SQL? At least I have the flags so only pos = 3 needs the percent format, pos = 1, 2 need the comma10.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried using a CASE WHEN but it doesn't work. If I have to do it in a DATA step, OK, but they won't allow a proc format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have tried it in PROC REPORT but the output dataset doesn't hold the formatting nor the new variable names.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HELP PLEASE! I'M DESPERATE&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Fri, 06 Dec 2024 22:56:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-format-a-variable-as-and-comma10-in-same-column-using/m-p/952808#M372353</guid>
      <dc:creator>SASGeek</dc:creator>
      <dc:date>2024-12-06T22:56:48Z</dc:date>
    </item>
    <item>
      <title>Re: How do I format a variable as % and comma10. in same column using proc sql?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-format-a-variable-as-and-comma10-in-same-column-using/m-p/952810#M372354</link>
      <description>&lt;P&gt;No, it cannot be done with numeric variables. The format is a variable (or column) attribute and is the same throughout the dataset. You can only do this in a report, or by storing the formatted values in a character variable.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Dec 2024 23:14:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-format-a-variable-as-and-comma10-in-same-column-using/m-p/952810#M372354</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-12-06T23:14:01Z</dc:date>
    </item>
    <item>
      <title>Re: How do I format a variable as % and comma10. in same column using proc sql?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-format-a-variable-as-and-comma10-in-same-column-using/m-p/952817#M372355</link>
      <description>&lt;P&gt;If you want a SAS data set with different formats on each row, I agree with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;it can't be done.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, if you want a REPORT, then it is possible in PROC REPORT. But of course this violates the "do everything in PROC SQL" rule and also that you want the results as a SAS dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if you're desperate, I'm afraid you are going to remain desperate. Perhaps you can convince your client that sometimes SQL can't do everything.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could use character variables, but of course then you can't perform arithmetic (like addition) or finding maximums from these character variables. (And then, it sounds like you want a report, not a data set)&lt;/P&gt;</description>
      <pubDate>Sat, 07 Dec 2024 00:02:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-format-a-variable-as-and-comma10-in-same-column-using/m-p/952817#M372355</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-12-07T00:02:46Z</dc:date>
    </item>
    <item>
      <title>Re: How do I format a variable as % and comma10. in same column using proc sql?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-format-a-variable-as-and-comma10-in-same-column-using/m-p/952818#M372356</link>
      <description>&lt;P&gt;Make the COL1 variable (what you called a COLUMN) a CHARACTER string.&amp;nbsp; Then you can store anything you want in it.&lt;/P&gt;
&lt;P&gt;So let's assume the data is currently in a dataset named HAVE with variables named DESCR, POS and NUMVAR.&amp;nbsp; Then you could use&amp;nbsp;SQL like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select descr
    , case when (pos=3) then put(numvar,percent6.) else put(numvar,comma10.) end as COL1
    , pos
from HAVE
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 07 Dec 2024 00:05:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-format-a-variable-as-and-comma10-in-same-column-using/m-p/952818#M372356</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-12-07T00:05:32Z</dc:date>
    </item>
    <item>
      <title>Re: How do I format a variable as % and comma10. in same column using proc sql?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-format-a-variable-as-and-comma10-in-same-column-using/m-p/952823#M372361</link>
      <description>&lt;P&gt;First, I agree that this problem is best be solved in a PROC REPORT.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But if you must somehow only use SQL, you would have to place a constraint on subranges of the column.&amp;nbsp; For instance, if you choose to only use values of -1 through +1 to represent -100% through 100%, and use only other values to be presented in comma format, you could do this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Take the sashelp.demographics dataset, with variables POP (actual population count) and POPURBAN (percentage represented as zero through one), put into the same column.&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;proc format;
  value pc  -1 - 1=[percentn10.2]
            other=[comma10.0];
run;

proc sql;
  create table want as 
  select name, 1 as row, pop as column_var format=pc10.2 from sashelp.demographics
  union
  select name, 2 as row, popurban as column_var  format=pc10.2 from sashelp.demographics
  order by name, calculated row
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 07 Dec 2024 04:32:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-format-a-variable-as-and-comma10-in-same-column-using/m-p/952823#M372361</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2024-12-07T04:32:53Z</dc:date>
    </item>
    <item>
      <title>Re: How do I format a variable as % and comma10. in same column using proc sql?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-format-a-variable-as-and-comma10-in-same-column-using/m-p/952846#M372369</link>
      <description>&lt;P&gt;Can you show the input dataset you have?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The goal is to make an output dataset with three columns and three rows?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can we assume&amp;nbsp; that the Col1 variable is a character variable?&lt;/P&gt;</description>
      <pubDate>Sat, 07 Dec 2024 16:22:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-format-a-variable-as-and-comma10-in-same-column-using/m-p/952846#M372369</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2024-12-07T16:22:07Z</dc:date>
    </item>
    <item>
      <title>Re: How do I format a variable as % and comma10. in same column using proc sql?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-format-a-variable-as-and-comma10-in-same-column-using/m-p/952856#M372374</link>
      <description>&lt;P&gt;Thank you Tom.&amp;nbsp; Brilliant. It doesn't HAVE to result in numeric output, just it has to look numeric. BRILLIANT.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Sat, 07 Dec 2024 17:28:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-format-a-variable-as-and-comma10-in-same-column-using/m-p/952856#M372374</guid>
      <dc:creator>SASGeek</dc:creator>
      <dc:date>2024-12-07T17:28:33Z</dc:date>
    </item>
  </channel>
</rss>

