<?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: reuse formatted variable in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/reuse-formatted-variable/m-p/594284#M15649</link>
    <description>&lt;P&gt;Unfortunately, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt; , the SQL interpreter doesn't consider a change of string length as a "calculation". Some function (such as substr) or operator must be involved for a new column name to be considered as CALCULATED :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt; 71         proc sql;
 72         select
 73         name length=2 as nm,
 74         case when calculated nm = "Ja" then "True" else "False" end as flag
 75         from sashelp.class;
 ERROR: The following columns were not found as CALCULATED references in the immediate query: nm.
 NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
 76         quit;
 NOTE: The SAS System stopped processing this step because of errors.&lt;/PRE&gt;</description>
    <pubDate>Sat, 05 Oct 2019 19:15:17 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2019-10-05T19:15:17Z</dc:date>
    <item>
      <title>reuse formatted variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/reuse-formatted-variable/m-p/594222#M15635</link>
      <description>&lt;P&gt;I'm trying to truncate the variable length to 30 and compare with another variable in the same query.&amp;nbsp;&lt;/P&gt;&lt;P&gt;can you help me with the below 2 questions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. How to reuse the formatted variable in the query&lt;/P&gt;&lt;P&gt;2. How to limit the length of variable in the case when statement.&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 sql;
create table data1 as select

NAME length =30 as name_formatted,
case when name_formatted = name_2 then 'true' else 'false'

from table 1 a

;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Oct 2019 20:16:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/reuse-formatted-variable/m-p/594222#M15635</guid>
      <dc:creator>sasuser_221</dc:creator>
      <dc:date>2019-10-04T20:16:42Z</dc:date>
    </item>
    <item>
      <title>Re: reuse formatted variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/reuse-formatted-variable/m-p/594256#M15644</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table data1 as 
select
	substr(NAME,1,30) as name_formatted length=30,
	case when calculated name_formatted = name_2 then 'true' else 'false' end as test
from table1;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 05 Oct 2019 03:40:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/reuse-formatted-variable/m-p/594256#M15644</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2019-10-05T03:40:44Z</dc:date>
    </item>
    <item>
      <title>Re: reuse formatted variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/reuse-formatted-variable/m-p/594258#M15645</link>
      <description>&lt;P&gt;You don't have any "formatted" variables, you aren't attaching formats to either of the two variables you are calculating.&lt;/P&gt;
&lt;P&gt;Did you mean a CALCULATED variable?&lt;/P&gt;
&lt;P&gt;Use the CALCULATED keyword to let the parser know that you are referring to a variable that was derived earlier in the list of columns being selected.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;create table data1 as 
  select
    NAME length =30 as name_formatted
  , case when CALCULATED name_formatted = name_2 then 'true'
         else 'false' 
    end as flag
from table1 a
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 05 Oct 2019 15:04:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/reuse-formatted-variable/m-p/594258#M15645</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-10-05T15:04:59Z</dc:date>
    </item>
    <item>
      <title>Re: reuse formatted variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/reuse-formatted-variable/m-p/594284#M15649</link>
      <description>&lt;P&gt;Unfortunately, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt; , the SQL interpreter doesn't consider a change of string length as a "calculation". Some function (such as substr) or operator must be involved for a new column name to be considered as CALCULATED :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt; 71         proc sql;
 72         select
 73         name length=2 as nm,
 74         case when calculated nm = "Ja" then "True" else "False" end as flag
 75         from sashelp.class;
 ERROR: The following columns were not found as CALCULATED references in the immediate query: nm.
 NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
 76         quit;
 NOTE: The SAS System stopped processing this step because of errors.&lt;/PRE&gt;</description>
      <pubDate>Sat, 05 Oct 2019 19:15:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/reuse-formatted-variable/m-p/594284#M15649</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2019-10-05T19:15:17Z</dc:date>
    </item>
    <item>
      <title>Re: reuse formatted variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/reuse-formatted-variable/m-p/594297#M15650</link>
      <description>&lt;P&gt;That is clearly a BUG. A change in name should be enough to require/allow the use of the CALCULATED keyword.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Given that limitation of PROC SQL you should use the SUBSTR() , or perhaps better the SUBSTRN() function to make sure it thinks you are calculating something.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 06 Oct 2019 00:08:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/reuse-formatted-variable/m-p/594297#M15650</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-10-06T00:08:29Z</dc:date>
    </item>
  </channel>
</rss>

