Date: Thu, 19 Jan 2012 12:20:36 -0800
Reply-To: "William W. Viergever" <william@VIERGEVER.NET>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "William W. Viergever" <william@VIERGEVER.NET>
Subject: Re: trimming last two characters from many variable names
In-Reply-To: <A83AA17321E97F4C908B78096448816501033F2A@SN2PRD0402MB110.namprd04.prod.outlook.com>
Content-Type: text/plain; charset="iso-8859-1"
LIKE
--------------------------------------------------------------
William W. Viergever
Viergever & Associates
Health Data Analysis / Systems Design & Development
2920 Arden Way Suite N
Sacramento, CA 95825
william@viergever.net
www.viergever.net
(916) 483-8398
--------------------------------------------------------------
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Zdeb, Michael S
Sent: Thursday, January 19, 2012 12:01 PM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Re: trimming last two characters from many variable names
hi ... here's one idea, let PROC SQL write most of a RENAME statement for use in PROC DATASETS ...
data x1;
retain xa_1 xb_1 xc_1 999;
run;
data x2;
retain xa_2 xb_2 xc_2 999;
run;
proc sql noprint;
select catt(name, '=' , substr(name,1, find(name,'_')-1)) into :rename1 separated by ' '
from dictionary.columns where libname eq 'WORK' and memname eq 'X1';
select catt(name, '=' , substr(name,1, find(name,'_')-1)) into :rename2 separated by ' '
from dictionary.columns where libname eq 'WORK' and memname eq 'X2';
quit;
proc datasets lib=work nolist;
modify x1;
rename &rename1 ;
modify x2;
rename &rename2 ;
quit;
Mike Zdeb
U@Albany School of Public Health
One University Place (Room 119)
Rensselaer, New York 12144-3456
P/518-402-6479 F/630-604-1475
________________________________________
From: SAS(r) Discussion [SAS-L@LISTSERV.UGA.EDU] on behalf of Alison [alisontetler@YAHOO.COM]
Sent: Thursday, January 19, 2012 1:03 PM
To: SAS-L@LISTSERV.UGA.EDU
Subject: trimming last two characters from many variable names
Hi all,
I am breaking up a horizontal dataset to restructure as vertical, and need
to rename many variables before setting the different datasets together.
Basically I have about 6 datasets now, with variables in first dataset:
Q404_1 Q405A_1 Q407AABB_1 for example (but with like 60 variables). Second
dataset variables are the same but with _2, and so forth and so on.
I am worried about making mistakes with using a rename array, and so I am
wondering how else I can program SAS to remove the right two characters from
these variable names.
Note that there are about 4 other variables in the dataset that do not have
the underscore number which should be excluded.
Thank you so much in advance,
Alison