BookmarkSubscribeRSS Feed
BURHAN_CIGDEM
Fluorite | Level 6

Hi,

I have a SAS dataset like that:

 

DateSalesBonus
2018010110050
2018010810251
2018011511053

 

All of variables are numeric format. Now, I would like to create a new SAS data set from previous dataset like this:

 

 010120180108201815012018
Sales100102110
Bonus505153

 

Please note that Date variables should be date format (ddmmyyyy).

 

how can I do this?

 

Any help will be appreciated.

4 REPLIES 4
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

Ksharp
Super User
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;
Astounding
PROC Star

@Ksharp's solution works, as long as you have properly set this option first:

 

options validvarname=any;

 

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;

 

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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. 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 921 views
  • 4 likes
  • 4 in conversation