dates used as column names

Accepted Solution Solved
Reply
Contributor
Posts: 27
Accepted Solution

dates used as column names

I am trying to put some dates such as '01jan1999'd as column name, but I can't work it out, is it possible?

If yes I would like to rename adjacent columns from  '01jan1999'd  to  '01jan2009'd, is it possible without writing alll the names?

alternatively I am thinking about putting the dates as records in a column and then doing a transpose,

but also here is there a fast method to put these names, like if it were a drag in excel?

thanks in advance


Accepted Solutions
Solution
‎02-10-2014 06:55 AM
Respected Advisor
Posts: 3,799

Re: dates used as column names

SAS enumerated variable lists can be incremented by 1 or -1 only as far as I know.  You seem to want an arbitrary increment in this case MONTH.  That's find but it does not work with enumerated variable lists.

If it were me I would keep the months/dates/ whatever as rows as long as possible.  Then when you need to have the months/dates/whatever become variables transpose to variables and LABEL the variables in a way that communicates the details of the data that you have placed in the meta data.  PROC TRANSPOSE statement IDLABEL will allow you to assign labels to the new variables using data.

Using a name prefix list you don't even have to know how many.

View solution in original post


All Replies
Super User
Posts: 5,431

Re: dates used as column names

First of all, why do you want them as columns at all? As you seem to already experienced yourself, it's not very convenient, neither for data manipulation programming nor reporting.

You say you can't work it. What have you tried? Showing som code might help.

You could achieve this by setting VALIDVARNAME = ANY, and use the name literal when specifying your column names.

Data never sleeps
Contributor
Posts: 27

Re: dates used as column names

I know that it's not convenient, but in this analysis is very helpful to know the exact month, e.g. 01march2002 instead of month47.

a trial would be like this, but it does not work

data base(rename=(month1-month180= '01jan1999'n  to  '01jan2009'n));set base;run;

Super User
Posts: 5,431

Re: dates used as column names

Seems easier to transpose your data, and the apply your date transformation on colmn values instead.

Data never sleeps
Solution
‎02-10-2014 06:55 AM
Respected Advisor
Posts: 3,799

Re: dates used as column names

SAS enumerated variable lists can be incremented by 1 or -1 only as far as I know.  You seem to want an arbitrary increment in this case MONTH.  That's find but it does not work with enumerated variable lists.

If it were me I would keep the months/dates/ whatever as rows as long as possible.  Then when you need to have the months/dates/whatever become variables transpose to variables and LABEL the variables in a way that communicates the details of the data that you have placed in the meta data.  PROC TRANSPOSE statement IDLABEL will allow you to assign labels to the new variables using data.

Using a name prefix list you don't even have to know how many.

🔒 This topic is solved and locked.

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

Discussion stats
  • 4 replies
  • 924 views
  • 3 likes
  • 3 in conversation