<?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: concatenating 2 variables in PROC SQL in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/concatenating-2-variables-in-PROC-SQL/m-p/264755#M269264</link>
    <description>&lt;P&gt;Thank you!&lt;/P&gt;
&lt;P&gt;But I am loosing the 'percent8.2' format. Any way to save that?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For ex: this is what I need in my output: &lt;STRONG&gt;177(28.34%)&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(where in my table I have the values for &amp;nbsp;f_N = 177, f_pct = 28.34% )&lt;/P&gt;</description>
    <pubDate>Tue, 19 Apr 2016 10:39:10 GMT</pubDate>
    <dc:creator>path2success</dc:creator>
    <dc:date>2016-04-19T10:39:10Z</dc:date>
    <item>
      <title>concatenating 2 variables in PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenating-2-variables-in-PROC-SQL/m-p/264750#M269262</link>
      <description>&lt;P&gt;&lt;BR /&gt;&lt;SPAN&gt;In a proc sql query I need to concatenate 2 character variables as 1 variable and those 2 variables are derived in the same sql query.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I want to know how to concatenate the 'derived' character variables within the same query.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;For&amp;nbsp;Ex:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;proc sql;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;create table x1 as&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;select n, put(f,best12.) as f_N, fem/n as f_pct format=percent8.2,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;cats(f_N, f_pct) as f_res /* *query fails here!**/&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;from T1;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;quit;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;TIA!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Apr 2016 10:20:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenating-2-variables-in-PROC-SQL/m-p/264750#M269262</guid>
      <dc:creator>path2success</dc:creator>
      <dc:date>2016-04-19T10:20:27Z</dc:date>
    </item>
    <item>
      <title>Re: concatenating 2 variables in PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenating-2-variables-in-PROC-SQL/m-p/264752#M269263</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/27622"&gt;@path2success﻿&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The CALCULATED keyword helps to avoid the "ERROR: The following columns were not found in the contributing tables: ...":&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;cats(calculated f_N, calculated f_pct) as f_res
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Whether the CATS function is the ideal way to concatenate these two values, is a different question ...&lt;/P&gt;</description>
      <pubDate>Tue, 19 Apr 2016 10:30:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenating-2-variables-in-PROC-SQL/m-p/264752#M269263</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-04-19T10:30:22Z</dc:date>
    </item>
    <item>
      <title>Re: concatenating 2 variables in PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenating-2-variables-in-PROC-SQL/m-p/264755#M269264</link>
      <description>&lt;P&gt;Thank you!&lt;/P&gt;
&lt;P&gt;But I am loosing the 'percent8.2' format. Any way to save that?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For ex: this is what I need in my output: &lt;STRONG&gt;177(28.34%)&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(where in my table I have the values for &amp;nbsp;f_N = 177, f_pct = 28.34% )&lt;/P&gt;</description>
      <pubDate>Tue, 19 Apr 2016 10:39:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenating-2-variables-in-PROC-SQL/m-p/264755#M269264</guid>
      <dc:creator>path2success</dc:creator>
      <dc:date>2016-04-19T10:39:10Z</dc:date>
    </item>
    <item>
      <title>Re: concatenating 2 variables in PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenating-2-variables-in-PROC-SQL/m-p/264756#M269265</link>
      <description>&lt;P&gt;Whilst I agree with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;that the calculated keyword solves the warning, you may consider what you are putting in that string, and doing implicit conversion or rounding:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  create table X1 as
  select  N, 
          put(F,best12.) as F_N, 
          FEM/N as F_PCT format=percent8.2,
          catx(',',put(F,best12.),round(FEM / N,.01)) as F_RES 
  from T1;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The above for instance, shows exactly what the variable F should look like, and what rounding should be applied to FEM / N - formats are a SAS thing, and are for display only - they do not change the value, so be specific about your rounding. &amp;nbsp;Also I changed it to catx as otherwise you wouldn't know where one value stopped and another started. &amp;nbsp;Also note consistent casing and indentation to make code easier to read.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Added: &amp;nbsp;If you want xx (pp%), then do:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;cat(put(F,best12.)," (",round(FEM / N,.01),"%)") as F_RES&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 06 Mar 2018 16:06:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenating-2-variables-in-PROC-SQL/m-p/264756#M269265</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-03-06T16:06:47Z</dc:date>
    </item>
    <item>
      <title>Re: concatenating 2 variables in PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenating-2-variables-in-PROC-SQL/m-p/264757#M269266</link>
      <description>&lt;P&gt;The format on a variable doesn't change the values in&amp;nbsp;the variable. So, when you concatenate F_PCT with something else, the PERCENT8.2 format is not involved at all. The result of a PUT function, however, gives the formatted value as a character string. You applied this technique already in the definition of f_N.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Apr 2016 10:45:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenating-2-variables-in-PROC-SQL/m-p/264757#M269266</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-04-19T10:45:25Z</dc:date>
    </item>
  </channel>
</rss>

