<?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: HOW TO REMOVE THE 3 FIRST LETTERS IN ALL THE VARIABLES NAMES in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/HOW-TO-REMOVE-THE-3-FIRST-LETTERS-IN-ALL-THE-VARIABLES-NAMES/m-p/336616#M76328</link>
    <description>&lt;P&gt;Here's another way:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA ALPHA;
UP_HOW=11;
UP_ARE=22;
UP_YOU=33;
run;

proc sql;
select count(*) into :varcount
from dictionary.columns
where libname='WORK'
and memname='ALPHA';
quit;

proc sql;
select name, substr(name,4) into :currname1-:currname3, :newname1-:newname3
from dictionary.columns
where libname='WORK'
and memname='ALPHA';
quit;

%macro changevarnames;
data ALPHA2;
set ALPHA;
%do j=1 %to &amp;amp;varcount.;
	rename &amp;amp;&amp;amp;currname&amp;amp;j.=&amp;amp;&amp;amp;newname&amp;amp;j.;
%end;
run;
%mend;

%changevarnames;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 28 Feb 2017 16:22:38 GMT</pubDate>
    <dc:creator>nehalsanghvi</dc:creator>
    <dc:date>2017-02-28T16:22:38Z</dc:date>
    <item>
      <title>HOW TO REMOVE THE 3 FIRST LETTERS IN ALL THE VARIABLES NAMES</title>
      <link>https://communities.sas.com/t5/SAS-Programming/HOW-TO-REMOVE-THE-3-FIRST-LETTERS-IN-ALL-THE-VARIABLES-NAMES/m-p/336612#M76326</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I have a file where all the variables start with a prefix I want to remove. These varables does not have a suffix and do not have a pattern in their name (like var1 var2 var3 etc.):&lt;/P&gt;
&lt;P&gt;So basically, I have:&lt;/P&gt;
&lt;P&gt;DATA ALPHA;&lt;/P&gt;
&lt;P&gt;UP_HOW=11;&lt;/P&gt;
&lt;P&gt;UP_ARE=22;&lt;/P&gt;
&lt;P&gt;UP_YOU=33; run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to remove the UP_ in the names.&lt;/P&gt;
&lt;P&gt;I have been trying with this macro, but I was unsuccessful:&lt;/P&gt;
&lt;P style="margin: 0cm 0cm 0pt 36pt;"&gt;&lt;FONT face="Verdana"&gt;&lt;STRONG&gt;&lt;SPAN style="background: white; color: navy; font-size: 11pt;"&gt;%macro&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN style="background: white; color: black; font-size: 11pt;"&gt; RenameList(vars= );&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="margin: 0cm 0cm 0pt 36pt;"&gt;&lt;FONT face="Verdana"&gt;&lt;SPAN style="background: white; color: black; font-size: 11pt;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="background: white; color: blue; font-size: 11pt;"&gt;%let&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-size: 11pt;"&gt; list=;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="margin: 0cm 0cm 0pt 36pt;"&gt;&lt;FONT face="Verdana"&gt;&lt;SPAN style="background: white; color: black; font-size: 11pt;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="background: white; color: green; font-size: 11pt;"&gt;*%do i = 1 %to %sysfunc(countw(&amp;amp;vars));&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="margin: 0cm 0cm 0pt 36pt;"&gt;&lt;FONT face="Verdana"&gt;&lt;SPAN style="background: white; color: black; font-size: 11pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="background: white; color: blue; font-size: 11pt;"&gt;%let&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-size: 11pt;"&gt; var=&lt;/SPAN&gt;&lt;SPAN style="background: white; color: blue; font-size: 11pt;"&gt;%substr&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-size: 11pt;"&gt;(&amp;amp;vars,4,50);&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="margin: 0cm 0cm 0pt 36pt;"&gt;&lt;FONT face="Verdana"&gt;&lt;SPAN style="background: white; color: black; font-size: 11pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="background: white; color: blue; font-size: 11pt;"&gt;%let&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-size: 11pt;"&gt; list= &amp;amp;var;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="margin: 0cm 0cm 0pt 36pt;"&gt;&lt;FONT face="Verdana"&gt;&lt;SPAN style="background: white; color: black; font-size: 11pt;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="background: white; color: blue; font-size: 11pt;"&gt;%end&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-size: 11pt;"&gt;;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="margin: 0cm 0cm 0pt 36pt;"&gt;&lt;SPAN style="background: white; color: black; font-size: 11pt;"&gt;&lt;FONT face="Verdana"&gt;&amp;nbsp;&amp;nbsp; &amp;amp;list&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin: 0cm 0cm 0pt 36pt;"&gt;&lt;FONT face="Verdana"&gt;&lt;STRONG&gt;&lt;SPAN style="background: white; color: navy; font-size: 11pt;"&gt;%mend&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN style="background: white; color: black; font-size: 11pt;"&gt;;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;Thanks for your help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Feb 2017 16:10:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/HOW-TO-REMOVE-THE-3-FIRST-LETTERS-IN-ALL-THE-VARIABLES-NAMES/m-p/336612#M76326</guid>
      <dc:creator>nketata</dc:creator>
      <dc:date>2017-02-28T16:10:44Z</dc:date>
    </item>
    <item>
      <title>Re: HOW TO REMOVE THE 3 FIRST LETTERS IN ALL THE VARIABLES NAMES</title>
      <link>https://communities.sas.com/t5/SAS-Programming/HOW-TO-REMOVE-THE-3-FIRST-LETTERS-IN-ALL-THE-VARIABLES-NAMES/m-p/336615#M76327</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can generate the renaming affectations as follows :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA ALPHA;
UP_HOW=11;
UP_ARE=22;
UP_YOU=33; 
run;

proc sql noprint;
	SELECT cats(NAME,"=",substr(NAME,4))
	INTO :renames SEPARATED BY " "
	FROM dictionary.columns
	WHERE LIBNAME="WORK" AND MEMNAME="ALPHA";
quit;

data want;
set Alpha;
rename &amp;amp;renames;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 28 Feb 2017 16:20:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/HOW-TO-REMOVE-THE-3-FIRST-LETTERS-IN-ALL-THE-VARIABLES-NAMES/m-p/336615#M76327</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2017-02-28T16:20:03Z</dc:date>
    </item>
    <item>
      <title>Re: HOW TO REMOVE THE 3 FIRST LETTERS IN ALL THE VARIABLES NAMES</title>
      <link>https://communities.sas.com/t5/SAS-Programming/HOW-TO-REMOVE-THE-3-FIRST-LETTERS-IN-ALL-THE-VARIABLES-NAMES/m-p/336616#M76328</link>
      <description>&lt;P&gt;Here's another way:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA ALPHA;
UP_HOW=11;
UP_ARE=22;
UP_YOU=33;
run;

proc sql;
select count(*) into :varcount
from dictionary.columns
where libname='WORK'
and memname='ALPHA';
quit;

proc sql;
select name, substr(name,4) into :currname1-:currname3, :newname1-:newname3
from dictionary.columns
where libname='WORK'
and memname='ALPHA';
quit;

%macro changevarnames;
data ALPHA2;
set ALPHA;
%do j=1 %to &amp;amp;varcount.;
	rename &amp;amp;&amp;amp;currname&amp;amp;j.=&amp;amp;&amp;amp;newname&amp;amp;j.;
%end;
run;
%mend;

%changevarnames;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 28 Feb 2017 16:22:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/HOW-TO-REMOVE-THE-3-FIRST-LETTERS-IN-ALL-THE-VARIABLES-NAMES/m-p/336616#M76328</guid>
      <dc:creator>nehalsanghvi</dc:creator>
      <dc:date>2017-02-28T16:22:38Z</dc:date>
    </item>
    <item>
      <title>Re: HOW TO REMOVE THE 3 FIRST LETTERS IN ALL THE VARIABLES NAMES</title>
      <link>https://communities.sas.com/t5/SAS-Programming/HOW-TO-REMOVE-THE-3-FIRST-LETTERS-IN-ALL-THE-VARIABLES-NAMES/m-p/336619#M76330</link>
      <description>&lt;P&gt;Food for thought:&amp;nbsp; Consider the possibility that you might be better off removing 2 characters instead of 3.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have a variable name like UP_3D, removing 3 characters will generate an invalid variable name.&amp;nbsp; Leaving the underscore in place will always create a valid variable name.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Feb 2017 16:34:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/HOW-TO-REMOVE-THE-3-FIRST-LETTERS-IN-ALL-THE-VARIABLES-NAMES/m-p/336619#M76330</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-02-28T16:34:21Z</dc:date>
    </item>
    <item>
      <title>Re: HOW TO REMOVE THE 3 FIRST LETTERS IN ALL THE VARIABLES NAMES</title>
      <link>https://communities.sas.com/t5/SAS-Programming/HOW-TO-REMOVE-THE-3-FIRST-LETTERS-IN-ALL-THE-VARIABLES-NAMES/m-p/336622#M76331</link>
      <description>&lt;P&gt;The question should be, why do you have that in the first place? &amp;nbsp;Either the data you have is fine and workable hence you have no need to rename, or the data is currently wrong, and you need to change the data before you get to this stage. &amp;nbsp;In most cases something further up the line is to blame, database export, data import not done right, etc. &amp;nbsp;There are many techincal avenues to do this process - you could datalines read in the data again, run a list of renames as given above etc. but that wouldn't exaplain the why of it.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Feb 2017 16:36:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/HOW-TO-REMOVE-THE-3-FIRST-LETTERS-IN-ALL-THE-VARIABLES-NAMES/m-p/336622#M76331</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-02-28T16:36:15Z</dc:date>
    </item>
    <item>
      <title>Re: HOW TO REMOVE THE 3 FIRST LETTERS IN ALL THE VARIABLES NAMES</title>
      <link>https://communities.sas.com/t5/SAS-Programming/HOW-TO-REMOVE-THE-3-FIRST-LETTERS-IN-ALL-THE-VARIABLES-NAMES/m-p/336624#M76332</link>
      <description>&lt;P&gt;For some reasons&lt;FONT color="#ff6600"&gt; the &lt;SPAN class="token keyword"&gt;FROM&lt;/SPAN&gt; dictionary&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;/FONT&gt;&lt;SPAN class="token keyword"&gt;&lt;FONT color="#ff6600"&gt;columns&lt;/FONT&gt; does not work;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token keyword"&gt;the macro variable &amp;nbsp;:renames is not created and cannot be called later.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Feb 2017 16:38:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/HOW-TO-REMOVE-THE-3-FIRST-LETTERS-IN-ALL-THE-VARIABLES-NAMES/m-p/336624#M76332</guid>
      <dc:creator>nketata</dc:creator>
      <dc:date>2017-02-28T16:38:35Z</dc:date>
    </item>
    <item>
      <title>Re: HOW TO REMOVE THE 3 FIRST LETTERS IN ALL THE VARIABLES NAMES</title>
      <link>https://communities.sas.com/t5/SAS-Programming/HOW-TO-REMOVE-THE-3-FIRST-LETTERS-IN-ALL-THE-VARIABLES-NAMES/m-p/336632#M76337</link>
      <description>What do you mean by "does not work". Which message in displayed in the log ?</description>
      <pubDate>Tue, 28 Feb 2017 16:47:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/HOW-TO-REMOVE-THE-3-FIRST-LETTERS-IN-ALL-THE-VARIABLES-NAMES/m-p/336632#M76337</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2017-02-28T16:47:17Z</dc:date>
    </item>
    <item>
      <title>Re: HOW TO REMOVE THE 3 FIRST LETTERS IN ALL THE VARIABLES NAMES</title>
      <link>https://communities.sas.com/t5/SAS-Programming/HOW-TO-REMOVE-THE-3-FIRST-LETTERS-IN-ALL-THE-VARIABLES-NAMES/m-p/336634#M76338</link>
      <description>&lt;P&gt;Well,&lt;/P&gt;
&lt;P&gt;I work for government so you can imagine my file does not have&amp;nbsp;3 variables.&lt;/P&gt;
&lt;P&gt;Second, I am in a process where the data are pushed to me; I have no control on the input&amp;nbsp;and the rename has to be dynamic because the&amp;nbsp; number of variables to be renamed can change.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Feb 2017 16:55:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/HOW-TO-REMOVE-THE-3-FIRST-LETTERS-IN-ALL-THE-VARIABLES-NAMES/m-p/336634#M76338</guid>
      <dc:creator>nketata</dc:creator>
      <dc:date>2017-02-28T16:55:23Z</dc:date>
    </item>
    <item>
      <title>Re: HOW TO REMOVE THE 3 FIRST LETTERS IN ALL THE VARIABLES NAMES</title>
      <link>https://communities.sas.com/t5/SAS-Programming/HOW-TO-REMOVE-THE-3-FIRST-LETTERS-IN-ALL-THE-VARIABLES-NAMES/m-p/336639#M76339</link>
      <description>&lt;P&gt;Here is a copy of the log:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;24318 proc sql noprint;&lt;/P&gt;
&lt;P&gt;24319 SELECT cats(NAME,"=",substr(NAME,4))&lt;/P&gt;
&lt;P&gt;24320 INTO :renames SEPARATED BY " "&lt;/P&gt;
&lt;P&gt;24321 FROM dictionary.columns&lt;/P&gt;
&lt;P&gt;24322 WHERE LIBNAME="WORK" AND MEMNAME="realfile";&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff6600"&gt;NOTE: No rows were selected.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;24323 quit;&lt;/P&gt;
&lt;P&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;/P&gt;
&lt;P&gt;real time 0.04 seconds&lt;/P&gt;
&lt;P&gt;cpu time 0.01 seconds&lt;/P&gt;
&lt;P&gt;　&lt;/P&gt;
&lt;P&gt;24324&lt;/P&gt;
&lt;P&gt;24325 data want;&lt;/P&gt;
&lt;P&gt;24326 set realfile;&lt;/P&gt;
&lt;P&gt;24327 rename &amp;amp;renames;&lt;/P&gt;
&lt;P&gt;-&lt;/P&gt;
&lt;P&gt;22&lt;/P&gt;
&lt;P&gt;200&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff6600"&gt;WARNING: Apparent symbolic reference RENAMES not resolved.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;ERROR 22-322: Syntax error, expecting one of the following: a name, ;.&lt;/P&gt;
&lt;P&gt;ERROR 200-322: The symbol is not recognized and will be ignored.&lt;/P&gt;
&lt;P&gt;24328 run;&lt;/P&gt;
&lt;P&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;/P&gt;
&lt;P&gt;WARNING: The data set WORK.WANT may be incomplete. When this step was stopped there were 0&lt;/P&gt;
&lt;P&gt;observations and 13 variables.&lt;/P&gt;
&lt;P&gt;NOTE: DATA statement used (Total process time):&lt;/P&gt;
&lt;P&gt;real time 0.01 seconds&lt;/P&gt;
&lt;P&gt;cpu time 0.01 seconds&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Feb 2017 17:19:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/HOW-TO-REMOVE-THE-3-FIRST-LETTERS-IN-ALL-THE-VARIABLES-NAMES/m-p/336639#M76339</guid>
      <dc:creator>nketata</dc:creator>
      <dc:date>2017-02-28T17:19:17Z</dc:date>
    </item>
    <item>
      <title>Re: HOW TO REMOVE THE 3 FIRST LETTERS IN ALL THE VARIABLES NAMES</title>
      <link>https://communities.sas.com/t5/SAS-Programming/HOW-TO-REMOVE-THE-3-FIRST-LETTERS-IN-ALL-THE-VARIABLES-NAMES/m-p/336644#M76340</link>
      <description>&lt;P&gt;Make sure the value for Memname is in all caps:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;MEMNAME="REALFILE"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All memname values in the dictionary.columns table are capitalized. Same goes for libname.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Feb 2017 17:23:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/HOW-TO-REMOVE-THE-3-FIRST-LETTERS-IN-ALL-THE-VARIABLES-NAMES/m-p/336644#M76340</guid>
      <dc:creator>nehalsanghvi</dc:creator>
      <dc:date>2017-02-28T17:23:01Z</dc:date>
    </item>
    <item>
      <title>Re: HOW TO REMOVE THE 3 FIRST LETTERS IN ALL THE VARIABLES NAMES</title>
      <link>https://communities.sas.com/t5/SAS-Programming/HOW-TO-REMOVE-THE-3-FIRST-LETTERS-IN-ALL-THE-VARIABLES-NAMES/m-p/336650#M76341</link>
      <description>&lt;P&gt;My bad . It works now.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Feb 2017 17:30:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/HOW-TO-REMOVE-THE-3-FIRST-LETTERS-IN-ALL-THE-VARIABLES-NAMES/m-p/336650#M76341</guid>
      <dc:creator>nketata</dc:creator>
      <dc:date>2017-02-28T17:30:06Z</dc:date>
    </item>
  </channel>
</rss>

