<?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 apply different formats when using set operators in proc sql? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-apply-different-formats-when-using-set-operators-in/m-p/896624#M354300</link>
    <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm trying to apply two formats to my code in proc SQL using the union operator. However, it only applies the first format that I listed. I can't show you actual code for confidentiality reasons however here is a sample code. Column 1 has ordinary numeric values while column 2 has a date format applied to it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select 'Total of column 1', sum('column 1'n) format=comma18.
from table1
union
select 'Max date of column 2', max('column 2'n) format=worddatx.
from table1;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 02 Oct 2023 09:41:15 GMT</pubDate>
    <dc:creator>CalebSindi</dc:creator>
    <dc:date>2023-10-02T09:41:15Z</dc:date>
    <item>
      <title>How do I apply different formats when using set operators in proc sql?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-apply-different-formats-when-using-set-operators-in/m-p/896624#M354300</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm trying to apply two formats to my code in proc SQL using the union operator. However, it only applies the first format that I listed. I can't show you actual code for confidentiality reasons however here is a sample code. Column 1 has ordinary numeric values while column 2 has a date format applied to it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select 'Total of column 1', sum('column 1'n) format=comma18.
from table1
union
select 'Max date of column 2', max('column 2'n) format=worddatx.
from table1;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 02 Oct 2023 09:41:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-apply-different-formats-when-using-set-operators-in/m-p/896624#M354300</guid>
      <dc:creator>CalebSindi</dc:creator>
      <dc:date>2023-10-02T09:41:15Z</dc:date>
    </item>
    <item>
      <title>Re: How do I apply different formats when using set operators in proc sql?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-apply-different-formats-when-using-set-operators-in/m-p/896627#M354301</link>
      <description>&lt;P&gt;My understanding here is that you are matching two input columns to one output column using UNION, and one column can only have one format at the time.&lt;/P&gt;
&lt;P&gt;Usually this is a non-no, but it looks like you are producing a report, and then it's fine.&lt;/P&gt;
&lt;P&gt;My suggestion is that you put the numerical value to char column using respective format:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;put(sum('column 1'n),comma18)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 02 Oct 2023 09:59:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-apply-different-formats-when-using-set-operators-in/m-p/896627#M354301</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2023-10-02T09:59:46Z</dc:date>
    </item>
    <item>
      <title>Re: How do I apply different formats when using set operators in proc sql?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-apply-different-formats-when-using-set-operators-in/m-p/896641#M354312</link>
      <description>&lt;P&gt;Thanks for the tip. I managed to crack it by creating macro variables. So it eventually looks something like this&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select sum('column 1'n) format=comma18.
into :Total trimmed
from table1;
quit;

proc SQL;
select distinct 'Sum of column 1', "&amp;amp;Total"
from table1;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 02 Oct 2023 10:35:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-apply-different-formats-when-using-set-operators-in/m-p/896641#M354312</guid>
      <dc:creator>CalebSindi</dc:creator>
      <dc:date>2023-10-02T10:35:44Z</dc:date>
    </item>
    <item>
      <title>Re: How do I apply different formats when using set operators in proc sql?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-apply-different-formats-when-using-set-operators-in/m-p/896664#M354319</link>
      <description>&lt;P&gt;Huh?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the goal was to just make that printout then why bother to make the dataset?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql ;
select sum('column 1'n) label='Sum of column 1' format=comma18. 
from table1;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 02 Oct 2023 13:26:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-apply-different-formats-when-using-set-operators-in/m-p/896664#M354319</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-10-02T13:26:30Z</dc:date>
    </item>
    <item>
      <title>Re: How do I apply different formats when using set operators in proc sql?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-apply-different-formats-when-using-set-operators-in/m-p/896677#M354323</link>
      <description>&lt;P&gt;The thing is, the printout is key because it will be used as a summary table that gets emailed to some stakeholders monthly.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Oct 2023 14:20:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-apply-different-formats-when-using-set-operators-in/m-p/896677#M354323</guid>
      <dc:creator>CalebSindi</dc:creator>
      <dc:date>2023-10-02T14:20:58Z</dc:date>
    </item>
    <item>
      <title>Re: How do I apply different formats when using set operators in proc sql?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-apply-different-formats-when-using-set-operators-in/m-p/896701#M354332</link>
      <description>&lt;P&gt;In that case you will want to generate the report using a reporting procedure like PROC REPORT.&amp;nbsp; Or perhaps even hand crafted using a DATA step.&amp;nbsp; PROC SQL is not a reporting tool.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Oct 2023 15:43:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-apply-different-formats-when-using-set-operators-in/m-p/896701#M354332</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-10-02T15:43:10Z</dc:date>
    </item>
  </channel>
</rss>

