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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 3 replies
  • 957 views
  • 0 likes
  • 3 in conversation