BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
marianhabesland
Calcite | Level 5

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?

1 ACCEPTED SOLUTION

Accepted Solutions
HB
Barite | Level 11 HB
Barite | Level 11

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.

View solution in original post

3 REPLIES 3
HB
Barite | Level 11 HB
Barite | Level 11

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.

marianhabesland
Calcite | Level 5

Thanks! Yeah, I just had to but a rename statement after the OUT = and the columns got renamed

Astounding
PROC Star

That looks right.  To gracefully rename the columns:

 

out=swimlog (rename=(_name_=Day col1=Minutes));

sas-innovate-wordmark-2025-midnight.png

Register Today!

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.


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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1280 views
  • 0 likes
  • 3 in conversation