<?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: Easy way to Readi n an Excel File with a Column Per Year? in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Easy-way-to-Readi-n-an-Excel-File-with-a-Column-Per-Year/m-p/433557#M28037</link>
    <description>&lt;P&gt;Is there a way to do a dynamic column rename?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To determine the new name I am looking at using the below logic.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt; &lt;STRONG&gt;sql&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; create table TestImportCols as&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select * from dictionary.columns&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /*where memname = 'TEST IMPORT'*/&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where memname = Column Categories';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;quit&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/*full list of column names*/&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; TestImportCols2 (keep=colname); set TestImportCols;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; length colname $200.;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if label ne '' then colname = label;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else colname = name;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;/*Then I run statements to clean up the text of colname, which can map back to the orginal column name.*/&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Data-Management/How-to-dynamically-rename-multiple-variables/td-p/182635" target="_blank"&gt;https://communities.sas.com/t5/SAS-Data-Management/How-to-dynamically-rename-multiple-variables/td-p/182635&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;This thread has:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"Do your long form variables meet SAS variable naming restrictions, i.e. 32 characters or less, no spaces, and starts with character?&lt;/P&gt;
&lt;P&gt;If they don't you'll want to set them as labels instead.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If so I usually do something like the following:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql noprint;&lt;/P&gt;
&lt;P&gt;select catx("=", old_name, new_name)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; into :rename_list separated by " "&lt;/P&gt;
&lt;P&gt;from key_dataset;&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc datasets library=work;&lt;/P&gt;
&lt;P&gt;modify my_data;&lt;/P&gt;
&lt;P&gt;rename &amp;amp;rename_list;&lt;/P&gt;
&lt;P&gt;run;"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I do not understand&amp;nbsp;the logic when dealing with labels due to over 32 characters.&lt;/P&gt;</description>
    <pubDate>Fri, 02 Feb 2018 15:18:58 GMT</pubDate>
    <dc:creator>DavidPhillips2</dc:creator>
    <dc:date>2018-02-02T15:18:58Z</dc:date>
    <item>
      <title>Easy way to Readi n an Excel File with a Column Per Year?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Easy-way-to-Readi-n-an-Excel-File-with-a-Column-Per-Year/m-p/432783#M27976</link>
      <description>&lt;P&gt;Is there a simple way to cleanly read in a file like the below description with SAS:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The Excel file has 2000 columns.&amp;nbsp; The data set contains five years of data where columns are split out by year.&lt;/P&gt;
&lt;P&gt;The column names are like:&lt;/P&gt;
&lt;P&gt;Grand total (EF2012B_RV&amp;nbsp; All Students total&amp;nbsp; All age categories total)&lt;/P&gt;
&lt;P&gt;Grand total (EF2013B_RV&amp;nbsp; All Students total&amp;nbsp; All age categories total)&lt;/P&gt;
&lt;P&gt;E.g. 2012 and 2013 are years.&lt;/P&gt;
&lt;P&gt;Years can be missing from the dataset.&amp;nbsp; So some columns for the years are missing.&lt;/P&gt;
&lt;P&gt;The length of the Excel column names are sometimes long 200 characters.&lt;/P&gt;
&lt;P&gt;Ideally I’d like to extract the year value and merge the columns and create a table with 400 columns.&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>Wed, 31 Jan 2018 15:19:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Easy-way-to-Readi-n-an-Excel-File-with-a-Column-Per-Year/m-p/432783#M27976</guid>
      <dc:creator>DavidPhillips2</dc:creator>
      <dc:date>2018-01-31T15:19:41Z</dc:date>
    </item>
    <item>
      <title>Re: Easy way to Readi n an Excel File with a Column Per Year?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Easy-way-to-Readi-n-an-Excel-File-with-a-Column-Per-Year/m-p/433030#M27999</link>
      <description>&lt;P&gt;Can't give you real code whitout sample data, but I think you can do it using the transpose task.&lt;/P&gt;
&lt;P&gt;You should be able to transpose the years to rows &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;//Fredrik&lt;/P&gt;</description>
      <pubDate>Thu, 01 Feb 2018 07:54:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Easy-way-to-Readi-n-an-Excel-File-with-a-Column-Per-Year/m-p/433030#M27999</guid>
      <dc:creator>FredrikE</dc:creator>
      <dc:date>2018-02-01T07:54:44Z</dc:date>
    </item>
    <item>
      <title>Re: Easy way to Readi n an Excel File with a Column Per Year?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Easy-way-to-Readi-n-an-Excel-File-with-a-Column-Per-Year/m-p/433118#M28011</link>
      <description>&lt;P&gt;Sample data is attached.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The goal is to merge columns together, so each column contains five values per school.&amp;nbsp; The year needs to be extracted into its own column.&amp;nbsp; When there is a column name over a particular length I would like to manually name it in a step.&amp;nbsp; Sufix text like _RV needs to be removed.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Feb 2018 14:43:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Easy-way-to-Readi-n-an-Excel-File-with-a-Column-Per-Year/m-p/433118#M28011</guid>
      <dc:creator>DavidPhillips2</dc:creator>
      <dc:date>2018-02-01T14:43:29Z</dc:date>
    </item>
    <item>
      <title>Re: Easy way to Readi n an Excel File with a Column Per Year?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Easy-way-to-Readi-n-an-Excel-File-with-a-Column-Per-Year/m-p/433557#M28037</link>
      <description>&lt;P&gt;Is there a way to do a dynamic column rename?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To determine the new name I am looking at using the below logic.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt; &lt;STRONG&gt;sql&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; create table TestImportCols as&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select * from dictionary.columns&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /*where memname = 'TEST IMPORT'*/&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where memname = Column Categories';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;quit&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/*full list of column names*/&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; TestImportCols2 (keep=colname); set TestImportCols;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; length colname $200.;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if label ne '' then colname = label;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else colname = name;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;/*Then I run statements to clean up the text of colname, which can map back to the orginal column name.*/&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Data-Management/How-to-dynamically-rename-multiple-variables/td-p/182635" target="_blank"&gt;https://communities.sas.com/t5/SAS-Data-Management/How-to-dynamically-rename-multiple-variables/td-p/182635&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;This thread has:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"Do your long form variables meet SAS variable naming restrictions, i.e. 32 characters or less, no spaces, and starts with character?&lt;/P&gt;
&lt;P&gt;If they don't you'll want to set them as labels instead.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If so I usually do something like the following:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql noprint;&lt;/P&gt;
&lt;P&gt;select catx("=", old_name, new_name)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; into :rename_list separated by " "&lt;/P&gt;
&lt;P&gt;from key_dataset;&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc datasets library=work;&lt;/P&gt;
&lt;P&gt;modify my_data;&lt;/P&gt;
&lt;P&gt;rename &amp;amp;rename_list;&lt;/P&gt;
&lt;P&gt;run;"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I do not understand&amp;nbsp;the logic when dealing with labels due to over 32 characters.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Feb 2018 15:18:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Easy-way-to-Readi-n-an-Excel-File-with-a-Column-Per-Year/m-p/433557#M28037</guid>
      <dc:creator>DavidPhillips2</dc:creator>
      <dc:date>2018-02-02T15:18:58Z</dc:date>
    </item>
    <item>
      <title>Re: Easy way to Readi n an Excel File with a Column Per Year?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Easy-way-to-Readi-n-an-Excel-File-with-a-Column-Per-Year/m-p/433577#M28038</link>
      <description>&lt;P&gt;It looks like I can simply reference the original column name rather than the label when doing the rename statement since both the label and original column name will be in the table.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Feb 2018 15:41:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Easy-way-to-Readi-n-an-Excel-File-with-a-Column-Per-Year/m-p/433577#M28038</guid>
      <dc:creator>DavidPhillips2</dc:creator>
      <dc:date>2018-02-02T15:41:02Z</dc:date>
    </item>
  </channel>
</rss>

