<?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: Changing column name when you only know the order in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Changing-column-name-when-you-only-know-the-order/m-p/444916#M111436</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/83078"&gt;@SuryaKiran&lt;/a&gt;&amp;nbsp;Thanks for the response.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've tried the following code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
	select nliteral(name)||"="||COMPRESS(name) INTO: Rename separated by " "
	from dictionary.columns
	where libname="WORK" and memname="lender_history_2018_01_31";
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;with the following result:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; NOTE: No rows were selected.
 77         run;
 NOTE: PROC SQL statements are executed immediately; The RUN statement has no effect.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Any idea of whats happening?&lt;/P&gt;</description>
    <pubDate>Mon, 12 Mar 2018 19:51:46 GMT</pubDate>
    <dc:creator>MikeFranz</dc:creator>
    <dc:date>2018-03-12T19:51:46Z</dc:date>
    <item>
      <title>Changing column name when you only know the order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-column-name-when-you-only-know-the-order/m-p/444881#M111421</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm&amp;nbsp;importing a .xlsx file into SAS Studio using PROC Import. Unfortunately, the names in Excel are strange, and I'm unable to reference them in SAS.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've run the following code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql; 
   describe table lender_history_2018_02_28;
  quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;while yields the following results:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;create table LENDER_HISTORY_2018_02_28( bufsize=65536 )
(
'CheckDate'n num format=MMDDYY10. label='CheckDate',
'CheckNumber'n char(5) format=$5. informat=$5. label='CheckNumber',
C num format=BEST. label='C',
D num format=BEST. label='D',
'Check Amount'n num format=NLMNY15.2 label='Check Amount',
'ServiceFees'n num format=NLMNY15.2 label='ServiceFees',
'Applied ToInterest'n num format=NLMNY15.2 label='Applied ToInterest',
'Applied ToPrincipal'n num format=NLMNY15.2 label='Applied ToPrincipal',
'Applied ToLate Charges'n num format=NLMNY15.2 label='Applied ToLate Charges',
'ChargesPrincipal'n num format=NLMNY15.2 label='ChargesPrincipal',
'ChargesInterest'n num format=NLMNY15.2 label='ChargesInterest',
'Applied ToPrepay Fee'n num format=NLMNY15.2 label='Applied ToPrepay Fee',
'OtherTaxable'n num format=NLMNY15.2 label='OtherTaxable',
'Applied ToNon-Taxable'n num format=NLMNY15.2 label='Applied ToNon-Taxable',
'OtherPayments'n num format=NLMNY15.2 label='OtherPayments',
'Applied ToTrust'n num format=NLMNY15.2 label='Applied ToTrust',
'LoanAccount'n char(10) format=$10. informat=$10. label='LoanAccount',
'Borrower Name'n char(45) format=$45. informat=$45. label='Borrower Name',
Notes char(78) format=$78. informat=$78. label='Notes',
'Check Memo'n char(20) format=$20. informat=$20. label='Check Memo',
'Created By'n char(9) format=$9. informat=$9. label='Created By',
'Date Created'n num format=DATETIME16. label='Date Created',
'Date Last Updated'n num format=DATETIME16. label='Date Last Updated',
'PaymentCode'n char(6) format=$6. informat=$6. label='PaymentCode',
'PaymentDate Due'n num format=MMDDYY10. label='PaymentDate Due',
'PaymentRcvd Date'n num format=MMDDYY10. label='PaymentRcvd Date'
);
&amp;nbsp;
75 quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;As you can see, the variable names (e.g. the&amp;nbsp; first one "'CheckDate'n") don't make sense, and I'm unable to reference them in later code. Unfortunately&amp;nbsp;we receive these files from a vendor, so I can't change them. Any ideas on how I could fix this? I think I could do one of two things:&lt;/P&gt;&lt;P&gt;1) Rename the&amp;nbsp;variables based on their&amp;nbsp;column number (the ordering is always the same)&lt;/P&gt;&lt;P&gt;2) Rename the&amp;nbsp;variables to their label, as these seem reasonable&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any ideas how I could do the above?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Mike&lt;/P&gt;</description>
      <pubDate>Mon, 12 Mar 2018 18:50:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-column-name-when-you-only-know-the-order/m-p/444881#M111421</guid>
      <dc:creator>MikeFranz</dc:creator>
      <dc:date>2018-03-12T18:50:20Z</dc:date>
    </item>
    <item>
      <title>Re: Changing column name when you only know the order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-column-name-when-you-only-know-the-order/m-p/444906#M111432</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/109914"&gt;@MikeFranz&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If your table has variables created with spaces then you can rename them using the dictionary.columns&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 nliteral(name)||"="||COMPRESS(name) INTO: Rename separated by " "
from dictionary.columns
where libname="WORK" and memname="TEST";
run;
DATA WANT;
SET TEST(Rename=(&amp;amp;rename.));
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;If your column name has other special characters like *&amp;amp;%$# then modify the COMPRESS function as needed. Also you can replace the variables names to Label names if the label names are valid, but we never know so try to convert it with variable names.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;nliteral(name)||"="||COMPRESS(label)&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Mar 2018 19:34:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-column-name-when-you-only-know-the-order/m-p/444906#M111432</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-03-12T19:34:39Z</dc:date>
    </item>
    <item>
      <title>Re: Changing column name when you only know the order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-column-name-when-you-only-know-the-order/m-p/444916#M111436</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/83078"&gt;@SuryaKiran&lt;/a&gt;&amp;nbsp;Thanks for the response.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've tried the following code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
	select nliteral(name)||"="||COMPRESS(name) INTO: Rename separated by " "
	from dictionary.columns
	where libname="WORK" and memname="lender_history_2018_01_31";
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;with the following result:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; NOTE: No rows were selected.
 77         run;
 NOTE: PROC SQL statements are executed immediately; The RUN statement has no effect.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Any idea of whats happening?&lt;/P&gt;</description>
      <pubDate>Mon, 12 Mar 2018 19:51:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-column-name-when-you-only-know-the-order/m-p/444916#M111436</guid>
      <dc:creator>MikeFranz</dc:creator>
      <dc:date>2018-03-12T19:51:46Z</dc:date>
    </item>
    <item>
      <title>Re: Changing column name when you only know the order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-column-name-when-you-only-know-the-order/m-p/444918#M111437</link>
      <description>&lt;P&gt;In Dictionary.columns the LIBNAME and MEMNAME values are in UPCASE so change it to upcase.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;PROC&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;SQL&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
	&lt;SPAN class="token statement"&gt;select&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;nliteral&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;name&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;||&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;"="&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;||&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;COMPRESS&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;name&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;INTO&lt;/SPAN&gt;: &lt;SPAN class="token function"&gt;Rename&lt;/SPAN&gt; separated &lt;SPAN class="token statement"&gt;by&lt;/SPAN&gt; &lt;SPAN class="token string"&gt;" "&lt;/SPAN&gt;
	&lt;SPAN class="token keyword"&gt;from&lt;/SPAN&gt; dictionary&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;columns&lt;/SPAN&gt;
	&lt;SPAN class="token statement"&gt;where&lt;/SPAN&gt; &lt;SPAN class="token statement"&gt;libname&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;"WORK"&lt;/SPAN&gt; and memname&lt;SPAN class="token operator"&gt;=UPCASE(&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;"lender_history_2018_01_31")&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 12 Mar 2018 19:55:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-column-name-when-you-only-know-the-order/m-p/444918#M111437</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-03-12T19:55:40Z</dc:date>
    </item>
    <item>
      <title>Re: Changing column name when you only know the order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-column-name-when-you-only-know-the-order/m-p/444921#M111438</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/83078"&gt;@SuryaKiran&lt;/a&gt;&amp;nbsp;Ah thank you. Ok, it now runs, with the following output:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;"Check Date"N=Check Date
"Check Number"N=Check Number
C =C
D =D
"Check Amount"N=CheckAmount
"Service Fees"N=Service Fees
"Applied To Interest"N=AppliedTo Interest
"Applied To Principal"N=AppliedTo Principal
"Applied To Late Charges"N=AppliedTo LateCharges
"Charges Principal"N=Charges Principal
"Charges Interest"N=Charges Interest
"Applied To Prepay Fee"N=AppliedTo PrepayFee
"Other Taxable"N=Other Taxable
"Applied To Non-Taxable"N=AppliedTo Non-Taxable
"Other Payments"N=Other Payments
"Applied To Trust"N=AppliedTo Trust
"Loan Account"N=Loan Account
"Borrower Name"N=BorrowerName
Notes =Notes
"Check Memo"N=CheckMemo
"Created By"N=CreatedBy
"Date Created"N=DateCreated
"Date Last Updated"N=DateLastUpdated
"Payment Code"N=Payment Code
"Payment Date Due"N=Payment DateDue
"Payment Rcvd Date"N=Payment RcvdDate&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Which I think is what we are looking to see.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, when I run the final datastep:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA WANT;
	SET work.lender_history_2018_01_31(Rename=(&amp;amp;rename.));
run;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I get the following error:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; 1          OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 72         
 73         DATA WANT;
 74         SET aaix.lender_history_2018_01_31(Rename=(&amp;amp;rename.));
 NOTE: Line generated by the macro variable "RENAME".
 74         "CheckDate"N=CheckDate "CheckNumber"N=CheckNumber C
                                       ________________
                                       79
 ERROR 79-322: Expecting a =.
 
 75         run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I think it's the "'NAME'n" causing issues?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Mike&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, 12 Mar 2018 20:00:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-column-name-when-you-only-know-the-order/m-p/444921#M111438</guid>
      <dc:creator>MikeFranz</dc:creator>
      <dc:date>2018-03-12T20:00:51Z</dc:date>
    </item>
    <item>
      <title>Re: Changing column name when you only know the order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-column-name-when-you-only-know-the-order/m-p/444932#M111442</link>
      <description>Try using&lt;BR /&gt;options validvarname=v7;&lt;BR /&gt;before proc import.</description>
      <pubDate>Mon, 12 Mar 2018 20:33:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-column-name-when-you-only-know-the-order/m-p/444932#M111442</guid>
      <dc:creator>error_prone</dc:creator>
      <dc:date>2018-03-12T20:33:08Z</dc:date>
    </item>
    <item>
      <title>Re: Changing column name when you only know the order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-column-name-when-you-only-know-the-order/m-p/444934#M111443</link>
      <description>&lt;P&gt;Did you use the COMPRESS function.&amp;nbsp;&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token string"&gt;"Check Date"&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;N&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;Check &lt;SPAN class="token function"&gt;Date&lt;/SPAN&gt;
&lt;SPAN class="token string"&gt;"Check Number"&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;N&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;Check Number /* There should not be space between Check and Number */
C &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;C
D &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;D&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 12 Mar 2018 20:44:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-column-name-when-you-only-know-the-order/m-p/444934#M111443</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-03-12T20:44:14Z</dc:date>
    </item>
    <item>
      <title>Re: Changing column name when you only know the order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-column-name-when-you-only-know-the-order/m-p/444941#M111444</link>
      <description>&lt;P&gt;In the variable names you have "-" so add that to COMPRESS function to remove. If you have any others characters then add them to list. Also add the third argument &lt;SPAN&gt;"s"&amp;nbsp;&lt;/SPAN&gt;to COMPRESS for removing&lt;SPAN&gt;&amp;nbsp;space characters (blank, horizontal tab, vertical tab, carriage return, line feed, and form feed)&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table LENDER_HISTORY_2018_02_28( bufsize=65536 )
(
'CheckDate'n num format=MMDDYY10. label='CheckDate',
'CheckNumber'n char(5) format=$5. informat=$5. label='CheckNumber',
C num format=BEST. label='C',
D num format=BEST. label='D',
'Check Amount'n num format=NLMNY15.2 label='Check Amount',
'ServiceFees'n num format=NLMNY15.2 label='ServiceFees',
'Applied ToInterest'n num format=NLMNY15.2 label='Applied ToInterest',
'Applied ToPrincipal'n num format=NLMNY15.2 label='Applied ToPrincipal',
'Applied ToLate Charges'n num format=NLMNY15.2 label='Applied ToLate Charges',
'ChargesPrincipal'n num format=NLMNY15.2 label='ChargesPrincipal',
'ChargesInterest'n num format=NLMNY15.2 label='ChargesInterest',
'Applied ToPrepay Fee'n num format=NLMNY15.2 label='Applied ToPrepay Fee',
'OtherTaxable'n num format=NLMNY15.2 label='OtherTaxable',
'Applied ToNon-Taxable'n num format=NLMNY15.2 label='Applied ToNon-Taxable',
'OtherPayments'n num format=NLMNY15.2 label='OtherPayments',
'Applied ToTrust'n num format=NLMNY15.2 label='Applied ToTrust',
'LoanAccount'n char(10) format=$10. informat=$10. label='LoanAccount',
'Borrower Name'n char(45) format=$45. informat=$45. label='Borrower Name',
Notes char(78) format=$78. informat=$78. label='Notes',
'Check Memo'n char(20) format=$20. informat=$20. label='Check Memo',
'Created By'n char(9) format=$9. informat=$9. label='Created By',
'Date Created'n num format=DATETIME16. label='Date Created',
'Date Last Updated'n num format=DATETIME16. label='Date Last Updated',
'PaymentCode'n char(6) format=$6. informat=$6. label='PaymentCode',
'PaymentDate Due'n num format=MMDDYY10. label='PaymentDate Due',
'PaymentRcvd Date'n num format=MMDDYY10. label='PaymentRcvd Date'
);
quit;

PROC SQL;
select nliteral(name)||"="||COMPRESS(name,'-','s') INTO: Rename separated by " "
from dictionary.columns
where libname="WORK" and MEMNAME="LENDER_HISTORY_2018_02_28";
quit;
 
DATA WANT;
SET LENDER_HISTORY_2018_02_28(Rename=(&amp;amp;rename));
Run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;It works fine for me, let me know if you have any issues&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Mar 2018 21:02:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-column-name-when-you-only-know-the-order/m-p/444941#M111444</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-03-12T21:02:58Z</dc:date>
    </item>
  </channel>
</rss>

