I am trying to create a dataset called work.swimlong; from the dataset work.swimminutes. You can see the format for work.swimminutes below in the instream data. I am trying to make work.swimlong in the format that the Mon, Tues, Wed variables are in collected in one variable called "Day", with the appropiate minutes by each day, like this:
Name Age Day Minutes
Ann 26 Mon 51
Ann 26 Tues 19
....
data work.swimminutes;
infile datalines delimiter = ',';
input Name :$5.
Age :2.
Mon :2.
Tues :2.
Wed :2.;
datalines;
Ann,26,51,19,22
Bob,30,43,20,60
Chris,41,48,.,36
Dina,21,32,57,22
;
proc transpose
data = work.swimminutes
out = work.swimlong;
Which Var or By statements do I need below to complete the code?
I think
proc transpose data=swimminutes
out=swimlog;
var mon tues wed;
by name age;
run;
Starts to move you in the right direction.
The SAS System | |||
Name | Age | NAME OF FORMER | COL1 |
VARIABLE | |||
Ann | 26 | Mon | 51 |
Ann | 26 | Tues | 19 |
Ann | 26 | Wed | 22 |
Bob | 30 | Mon | 43 |
Bob | 30 | Tues | 20 |
Bob | 30 | Wed | 60 |
Chris | 41 | Mon | 48 |
Chris | 41 | Tues | . |
Chris | 41 | Wed | 36 |
Dina | 21 | Mon | 32 |
Dina | 21 | Tues | 57 |
Dina | 21 | Wed | 22 |
I don't know how to gracefully rename the columns to Day and Minutes.
I think
proc transpose data=swimminutes
out=swimlog;
var mon tues wed;
by name age;
run;
Starts to move you in the right direction.
The SAS System | |||
Name | Age | NAME OF FORMER | COL1 |
VARIABLE | |||
Ann | 26 | Mon | 51 |
Ann | 26 | Tues | 19 |
Ann | 26 | Wed | 22 |
Bob | 30 | Mon | 43 |
Bob | 30 | Tues | 20 |
Bob | 30 | Wed | 60 |
Chris | 41 | Mon | 48 |
Chris | 41 | Tues | . |
Chris | 41 | Wed | 36 |
Dina | 21 | Mon | 32 |
Dina | 21 | Tues | 57 |
Dina | 21 | Wed | 22 |
I don't know how to gracefully rename the columns to Day and Minutes.
Thanks! Yeah, I just had to but a rename statement after the OUT = and the columns got renamed
That looks right. To gracefully rename the columns:
out=swimlog (rename=(_name_=Day col1=Minutes));
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.