<?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: Handling / Differentiating identically named variables in source table in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Handling-Differentiating-identically-named-variables-in-source/m-p/545769#M151043</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've tried this, but I'm continuing to receive this message:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;PROC SQL;

create table testing
as select
'consolidated_arrears_vs_portfolio_balance_chl'n
&lt;FONT color="#FF0000"&gt;____________________________________________
65
ERROR 65-58: Name ''consolidated_arrears_vs_portfolio_balance_chl'N' is too long for a SAS name in this context.&lt;/FONT&gt;

FROM REP.va_me_local;
run;&lt;/PRE&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;I have also included the &lt;/FONT&gt;&lt;/P&gt;&lt;PRE&gt;options validvarname=any;&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;prior to this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 25 Mar 2019 12:12:27 GMT</pubDate>
    <dc:creator>Seb_A_Sanders</dc:creator>
    <dc:date>2019-03-25T12:12:27Z</dc:date>
    <item>
      <title>Handling / Differentiating identically named variables in source table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Handling-Differentiating-identically-named-variables-in-source/m-p/545749#M151033</link>
      <description>&lt;P&gt;The database setup at my organisation is SQL Server tables copied onto our SAS server. The SQL tables were setup to run pre-programmed SQL queries, but now SAS is the tool used. This however creates an issue with some tables having variables that are too long for SAS, but work in SQL. The label for the source variable is correct and not shortened.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The source table (in SQL Server) names:&lt;/P&gt;&lt;P&gt;Consolidated_Arrears_Vs_Portfolio_Balance_Ltd&lt;/P&gt;&lt;P&gt;Consolidated_Arrears_Vs_Portfolio_Balance_Pure&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In SAS:&lt;/P&gt;&lt;P&gt;Consolidated_Arrears_Vs_Portfoli&lt;/P&gt;&lt;P&gt;Consolidated_Arrears_Vs_Portfoli&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SAS Labels:&lt;/P&gt;&lt;P&gt;Consolidated_Arrears_Vs_Portfolio_Balance_Ltd&lt;/P&gt;&lt;P&gt;Consolidated_Arrears_Vs_Portfolio_Balance_Pure&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, how do I tell the difference between these two when I'm writing code / query builder?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(I have no control over the SQL Server code so I can't change the underlying tables or how these are copied to the SAS server)&lt;/P&gt;</description>
      <pubDate>Mon, 25 Mar 2019 11:35:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Handling-Differentiating-identically-named-variables-in-source/m-p/545749#M151033</guid>
      <dc:creator>Seb_A_Sanders</dc:creator>
      <dc:date>2019-03-25T11:35:00Z</dc:date>
    </item>
    <item>
      <title>Re: Handling / Differentiating identically named variables in source table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Handling-Differentiating-identically-named-variables-in-source/m-p/545757#M151039</link>
      <description>&lt;P&gt;Use named literals:&lt;/P&gt;
&lt;PRE&gt;select 'consolidated_arrears_vs_portfolio_balance_ltd'n&lt;/PRE&gt;
&lt;P&gt;Note the quotes and the n.&amp;nbsp; Or you can set:&lt;/P&gt;
&lt;PRE&gt;options validvarname=any;&lt;/PRE&gt;
&lt;P&gt;Which basically means you can write any old rubbish you like, and the next guy will love you for it.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Mar 2019 11:49:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Handling-Differentiating-identically-named-variables-in-source/m-p/545757#M151039</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2019-03-25T11:49:46Z</dc:date>
    </item>
    <item>
      <title>Re: Handling / Differentiating identically named variables in source table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Handling-Differentiating-identically-named-variables-in-source/m-p/545769#M151043</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've tried this, but I'm continuing to receive this message:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;PROC SQL;

create table testing
as select
'consolidated_arrears_vs_portfolio_balance_chl'n
&lt;FONT color="#FF0000"&gt;____________________________________________
65
ERROR 65-58: Name ''consolidated_arrears_vs_portfolio_balance_chl'N' is too long for a SAS name in this context.&lt;/FONT&gt;

FROM REP.va_me_local;
run;&lt;/PRE&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;I have also included the &lt;/FONT&gt;&lt;/P&gt;&lt;PRE&gt;options validvarname=any;&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;prior to this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Mar 2019 12:12:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Handling-Differentiating-identically-named-variables-in-source/m-p/545769#M151043</guid>
      <dc:creator>Seb_A_Sanders</dc:creator>
      <dc:date>2019-03-25T12:12:27Z</dc:date>
    </item>
    <item>
      <title>Re: Handling / Differentiating identically named variables in source table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Handling-Differentiating-identically-named-variables-in-source/m-p/545774#M151046</link>
      <description>&lt;P&gt;The validvarname=any option permits special characters and embedded blanks (and leading blanks) in name literals. But unfortunately it does not escape the 32-byte limit.&amp;nbsp; You'll need another approach.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Mar 2019 12:24:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Handling-Differentiating-identically-named-variables-in-source/m-p/545774#M151046</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2019-03-25T12:24:52Z</dc:date>
    </item>
    <item>
      <title>Re: Handling / Differentiating identically named variables in source table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Handling-Differentiating-identically-named-variables-in-source/m-p/545775#M151047</link>
      <description>&lt;P&gt;I don't know if this will work, but it's worth testing.&amp;nbsp; Have you tried shortening the name on the fly, something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;select&amp;nbsp;&lt;SPAN&gt;Consolidated_Arrears_Vs_Portfolio_Balance_Ltd as Cons_Arrears_vs_Port_Bal_Ltd&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Mar 2019 12:29:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Handling-Differentiating-identically-named-variables-in-source/m-p/545775#M151047</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-03-25T12:29:57Z</dc:date>
    </item>
    <item>
      <title>Re: Handling / Differentiating identically named variables in source table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Handling-Differentiating-identically-named-variables-in-source/m-p/545779#M151050</link>
      <description>&lt;P&gt;Ah, ok then.&amp;nbsp; Looks like your oing to have to go down one of these routes:&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SAS-Data-Management/Long-SQL-Server-via-ODBC-table-names-amp-column-names/td-p/356253" target="_blank"&gt;https://communities.sas.com/t5/SAS-Data-Management/Long-SQL-Server-via-ODBC-table-names-amp-column-names/td-p/356253&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Mar 2019 12:32:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Handling-Differentiating-identically-named-variables-in-source/m-p/545779#M151050</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2019-03-25T12:32:37Z</dc:date>
    </item>
    <item>
      <title>Re: Handling / Differentiating identically named variables in source table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Handling-Differentiating-identically-named-variables-in-source/m-p/545783#M151054</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/79326"&gt;@Seb_A_Sanders&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think your only way out of the problem is to use SQL passthru. This way you can handle +32 long names of both tables and columns. Se the following code, which is a subset of working production code cut down to 3 variables:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options Validvarname = V7;
proc sql;

    connect using xkmdne as sconn;

    create table &amp;amp;_OUTPUT (label="archive_NEXUS2_medicine_medication_additional_information") as
        select 
			medication_id 
				length=8 ,
             administratively_deleted_datetim
                length=8
                format=nldatm20.
                label="administratively_deleted_datetime" ,
             last_past_fmk_dosage_period_end_
                length=8
                format=ddmmyyd10.
                label="last_past_fmk_dosage_period_end_date" 

        from connection to sconn (
            select
                medication_id,
                administratively_deleted_datetime     
					as administratively_deleted_datetim,
                last_past_fmk_dosage_period_end_date  
					as last_past_fmk_dosage_period_end_
            from archive_NEXUS2_medicine_medication_additional_information
        );

    disconnect from sconn;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Explanation:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Make a connection to&amp;nbsp;the relevant SQL database using a previously assigned libname to the database.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Create a new SAS table with name abbreviated to 32 chars. Use original SQL table name as dataset label.&amp;nbsp;select from connection to database, use original SQL column names as variable labels.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Connection to database gives the result of the second select, where long column names are abbreviated to sonething useful. This select is sent to execution in the database, so all long names are kept on the SQL Server side, and SAS sees only your abbreviations.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Mar 2019 12:44:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Handling-Differentiating-identically-named-variables-in-source/m-p/545783#M151054</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2019-03-25T12:44:01Z</dc:date>
    </item>
  </channel>
</rss>

