04-24-2018 04:22 AM
I have a SAS dataset like that:
All of variables are numeric format. Now, I would like to create a new SAS data set from previous dataset like this:
Please note that Date variables should be date format (ddmmyyyy).
how can I do this?
Any help will be appreciated.
04-24-2018 04:58 AM
You cannot. Variable names should start with an A-Z or underscore. You can set the label to be the date and have variable name as d then date:
data have; input date $ sales bonus; datalines; 20180101 100 50 20180108 102 51 20180115 110 53 ; run; proc transpose data=have out=inter; by date; var sales bonus; run; proc sort data=inter; by _name_ date; run; proc transpose data=inter out=want prefix=d; by _name_; var col1; id date; idlabel date; run;
Unless it is for an output file though I would really recommend against it. You will find the data far harder to program against, just knowing what variables you have becomes a whole set of code in itself then.
04-24-2018 08:27 AM
data have; input date $ sales bonus; datalines; 20180101 100 50 20180108 102 51 20180115 110 53 ; run; proc transpose data=have out=want; id date; var sales bonus; run;
04-24-2018 09:31 AM
@Ksharp's solution works, as long as you have properly set this option first:
That's what allows you to use variable names (such as the date values) that would not normally be permitted. Also note that you will have to refer to your variable names a little differently going forward. This will not work:
var 20180101 20180108 20180115;
Instead, you will need to use:
var '20180101'n '20180108'n '20180115'n;
04-24-2018 10:00 AM
Which in any production environment is to be used with extreme caution. Any programming language is based on fundamental rules, it helps with programming for instance, and this option is effectively saying do whatever you like. Even in that simple example coding has become far harder as you need quotes, the extra character, lose the ability to array them simply, or refer to them in lists. Its just a very bad idea.