<?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: Using Proc SQL to rename variables in a large data set containing many variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-Proc-SQL-to-rename-variables-in-a-large-data-set/m-p/324871#M72163</link>
    <description>&lt;P&gt;You may combine&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;'s code with next code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; select &amp;nbsp;1 as var01,&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2 as var02,&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3 as var03&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; from sashelp.class;&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and if possible, if you use excel as mid file that contains variable sequence and variable names&lt;/P&gt;
&lt;P&gt;then I suggest to put the original name as a label to the sas variable name.&lt;/P&gt;</description>
    <pubDate>Sun, 15 Jan 2017 06:05:30 GMT</pubDate>
    <dc:creator>Shmuel</dc:creator>
    <dc:date>2017-01-15T06:05:30Z</dc:date>
    <item>
      <title>Using Proc SQL to rename variables in a large data set containing many variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Proc-SQL-to-rename-variables-in-a-large-data-set/m-p/324844#M72145</link>
      <description>&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; CREATE TABLE LIBXYZ.DEVELOPMENT_SAMPLE_03&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; AS&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; SELECT&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; T1.CONTRACTNO ,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; T1.FLAG &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;AS BIN_TARGET , /* BINARY TARGET */&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; T1.DELPHI_ADDRESS_LINK_NDLNK01_ADDR &amp;nbsp; &amp;nbsp; &amp;nbsp;AS VAR_0001 ,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; T1.DELPHI_APACCS_CCDATASUPPLIED_APA &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; AS VAR_0002 ,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; T1.DELPHI_CAIS_E1B03_WORST_STATUS_L &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; AS VAR_0003 ,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; T1.DELPHI_CAIS_E1B05_WORST_STATUS_L &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; AS VAR_0004 ,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; T1.DELPHI_CAIS_E1B07_WORST_STATUS_L &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; AS VAR_0005 ,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; T1.SPB113 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;AS VAR_0267&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;FROM &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; LIBXYZ.DEVELOPMENT_SAMPLE_02 &amp;nbsp; T1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;ORDER BY &amp;nbsp; &amp;nbsp;T1.CONTRACTNO;&lt;/P&gt;&lt;P&gt;&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;The renaming technique in the above SQL code is very manual and time-consuming as well as being "hard-coded" and therefore difficult to make consistent changes&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a data set containing several hundred variables with very long names ( lots with names&amp;nbsp;greater than 32 characters and in some cases the first 32 characters are identical across distinct variables )&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to rename all these variables : Var_Long_Name_01 &amp;nbsp;to Var_0001 as indicated in the SQL Code above.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there some simple way in which I can do this without having to type in the new name for each of the several hundred variables?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The solution can involve base SAS, SQL or even Excel !!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your help&lt;/P&gt;</description>
      <pubDate>Sat, 14 Jan 2017 23:53:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Proc-SQL-to-rename-variables-in-a-large-data-set/m-p/324844#M72145</guid>
      <dc:creator>JonDickens1607</dc:creator>
      <dc:date>2017-01-14T23:53:42Z</dc:date>
    </item>
    <item>
      <title>Re: Using Proc SQL to rename variables in a large data set containing many variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Proc-SQL-to-rename-variables-in-a-large-data-set/m-p/324846#M72147</link>
      <description>&lt;P&gt;How are you deciding order on the variables?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can fudge this, since it's likely a one time solution, use either proc contents OR dictionary.columns table to get all column names. Paste into Excel, in a single column. Use the autofill to generate the names in the column beside it. Then use concatenate function in Excel to generate the string: &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;CONCATENATE(A2, " AS ", B2, ",")&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then, copy and paste that into your code editor.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Because you have several hundred variables you can also use a code solution but it's a touch more tedious since you'll run out of space for a single macro variable so you'll have to create multiple macro variables. &amp;nbsp;If there's ANY chance of needing to repeat this, I'd probably code a solution. &amp;nbsp;I've used the above method in a pinch, for quick ad hocs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 15 Jan 2017 00:43:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Proc-SQL-to-rename-variables-in-a-large-data-set/m-p/324846#M72147</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-01-15T00:43:33Z</dc:date>
    </item>
    <item>
      <title>Re: Using Proc SQL to rename variables in a large data set containing many variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Proc-SQL-to-rename-variables-in-a-large-data-set/m-p/324849#M72150</link>
      <description>&lt;P&gt;You also most likely will have to use SQL &amp;nbsp;Pass Thru at some point, because if the table has more than 32 chars you won't be able to access it in SAS. &amp;nbsp;Here's an idea of how that process will work, if it was all in SAS...not sure how to deal with vars longer than 32 chars.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data class;
    set sashelp.class;
run;

/*Create macro variables*/
data _null_;
    set sashelp.vcolumn (keep=name varnum libname memname 
        where=(%upcase(libname)="WORK" and %upcase(memname)="CLASS")) end=eof;
    string=catx (" as ", name, catt("VAR_", put(varnum, z5.)));

    if not eof then
        call symputx(catt("VAR_", put(varnum, 8. -l)), trim(string)||",", 'g');
    else
        do;
            call symputx(catt("VAR_", put(varnum, 8. -l)), string, 'g');
            call symputx('nvars', _n_, 'g');
        end;
run;

/*Macro to display macro variables*/
%macro rename();
    %do i=1 %to &amp;amp;nvars;
        &amp;amp;&amp;amp;&amp;amp;var_&amp;amp;i
%end;
%mend;

*Rename process;

proc sql ;
    create table want as select %rename() from class;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 15 Jan 2017 01:05:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Proc-SQL-to-rename-variables-in-a-large-data-set/m-p/324849#M72150</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-01-15T01:05:45Z</dc:date>
    </item>
    <item>
      <title>Re: Using Proc SQL to rename variables in a large data set containing many variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Proc-SQL-to-rename-variables-in-a-large-data-set/m-p/324871#M72163</link>
      <description>&lt;P&gt;You may combine&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;'s code with next code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; select &amp;nbsp;1 as var01,&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2 as var02,&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3 as var03&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; from sashelp.class;&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and if possible, if you use excel as mid file that contains variable sequence and variable names&lt;/P&gt;
&lt;P&gt;then I suggest to put the original name as a label to the sas variable name.&lt;/P&gt;</description>
      <pubDate>Sun, 15 Jan 2017 06:05:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Proc-SQL-to-rename-variables-in-a-large-data-set/m-p/324871#M72163</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-01-15T06:05:30Z</dc:date>
    </item>
    <item>
      <title>Re: Using Proc SQL to rename variables in a large data set containing many variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Proc-SQL-to-rename-variables-in-a-large-data-set/m-p/324881#M72166</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your input&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The context or &amp;nbsp;potential application scenarios are as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. Building an Credit Risk Management Application Scorecard Model that is based on both Internal and External Predictor Variables.&lt;/P&gt;&lt;P&gt;2. The External Variables are a mix of Numeric and Character Variables from a Credit Risk Agency ( Names &amp;gt; 32 characters )&lt;/P&gt;&lt;P&gt;3. The data includes variables with:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; all missing values, &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; constant values across all rows,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; large numbers of missing values etc&lt;/P&gt;&lt;P&gt;4. High Dimensionality of the data space is a significant challenge:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; Some variables are binary while others are continuous with extended ranges&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The main issue during Exploratory Data Analysis and Dimension Reduction involves separating Numeric Variables from Character Variables and then applying the appropriate techniques to each subset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Because the model often involves binary logistic regression, we can use Weight Of Evidence and Information Value, to transform all the numeric variables onto a common scale and to then rank them in terms of predictive power...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The second application will involve monthly scorreacrd monitoring reports using a relatively fixed set of scorecard variables.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As a once-off solution I think that the Excel Solution is probably the most efficient ( it is the one that we currently use ) but for ongoing work it would be good to automate the process within SAS as much as possible.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;We are working with the SQL team to construct views of the data tables that we can use in SAS to overcome the 32 character name issue&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 15 Jan 2017 11:50:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Proc-SQL-to-rename-variables-in-a-large-data-set/m-p/324881#M72166</guid>
      <dc:creator>JonDickens1607</dc:creator>
      <dc:date>2017-01-15T11:50:52Z</dc:date>
    </item>
    <item>
      <title>Re: Using Proc SQL to rename variables in a large data set containing many variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Proc-SQL-to-rename-variables-in-a-large-data-set/m-p/324882#M72167</link>
      <description>&lt;P&gt;Thanks for your kind assistance&lt;/P&gt;</description>
      <pubDate>Sun, 15 Jan 2017 11:53:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Proc-SQL-to-rename-variables-in-a-large-data-set/m-p/324882#M72167</guid>
      <dc:creator>JonDickens1607</dc:creator>
      <dc:date>2017-01-15T11:53:50Z</dc:date>
    </item>
    <item>
      <title>Re: Using Proc SQL to rename variables in a large data set containing many variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Proc-SQL-to-rename-variables-in-a-large-data-set/m-p/324883#M72168</link>
      <description>&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Sun, 15 Jan 2017 11:54:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Proc-SQL-to-rename-variables-in-a-large-data-set/m-p/324883#M72168</guid>
      <dc:creator>JonDickens1607</dc:creator>
      <dc:date>2017-01-15T11:54:44Z</dc:date>
    </item>
  </channel>
</rss>

