Desktop productivity for business analysts and programmers

how to rename a range of variables from 'H-AW' to '1980-2021'

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

how to rename a range of variables from 'H-AW' to '1980-2021'

Hi guys,

 

I imported an excel stats dataset into SAS EG and the year fields  "1980-2021" were output as "H=AW". I want to rename these variable names back to "1980-2021" for analysis.

 

I tried (excerpt):


rename H=1980 I=1981 J=1982 K=1983 L=1984 M=1985 N=1986 O=1987 P=1988 Q=1989 R=1990 S=1991 T=1992
U=1993 V=1994 W=1995 X=1996 Y=1997 Z=1998 AA=1999 AB=2000 AC=2001 AD=2002 AE=2003 AF=2004
AG=2005 AH=2006 AI=2007 AJ=2008 AK=2009 AL=2010 AM=2011 AN=2012 AO=2013 AP=2014 AQ=2015 AR=2016
AS=2017 AT=2018 AU=2019 AV=2020 AW=2021;

 

but got the error messsage (excerpt): 


rename H=1980 I=1981 J=1982 K=1983 L=1984 M=1985 N=1986 O=1987 P=1988 Q=1989 R=1990 S=1991 T=1992
____
22
76
ERROR 22-322: Expecting a name.

ERROR 76-322: Syntax error, statement will be ignored.

 

Any help?

 

Thanks


Accepted Solutions
Solution
‎03-09-2017 11:23 AM
Super User
Posts: 19,064

Re: how to rename a range of variables from 'H-AW' to '1980-2021'

Those aren't valid SAS names, it needs a letter or underscore before the number. SAS variable name rules

 

 

rename h=Y1980 i=Y1981;

 

You could try the following but I'm not sure it will recognize the first set of variables as a sequence.

 

rename h-av = Y1980-Y2021;

View solution in original post


All Replies
Solution
‎03-09-2017 11:23 AM
Super User
Posts: 19,064

Re: how to rename a range of variables from 'H-AW' to '1980-2021'

Those aren't valid SAS names, it needs a letter or underscore before the number. SAS variable name rules

 

 

rename h=Y1980 i=Y1981;

 

You could try the following but I'm not sure it will recognize the first set of variables as a sequence.

 

rename h-av = Y1980-Y2021;
New Contributor
Posts: 2

Re: how to rename a range of variables from 'H-AW' to '1980-2021'

Worked. Thanks a million.

Super User
Posts: 11,115

Re: how to rename a range of variables from 'H-AW' to '1980-2021'


kinassan wrote:

Hi guys,

 

I imported an excel stats dataset into SAS EG and the year fields  "1980-2021" were output as "H=AW". I want to rename these variable names back to "1980-2021" for analysis.

 

 


You might consider going back to the import step and make sure ot use the GETNAMES option. If your data sheet has the names other than row one, delete those rows so the column names are just above the data.

 

Merged cells are right out though.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 184 views
  • 1 like
  • 3 in conversation