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

Hi All,

I have a dataset below that I would like to transpose from wide to long format. I've always struggled with getting proc transpose to do what I envision but thinking that proc transpose can't handle this request. I have many other measurements and time periods so hopefully there is some method out there that can handle more than what I am presenting here in the data.

 

data have;
  input id approach diet time1 measure1_1 measure2_1 $ time2 measure1_2 measure2_2 $ time3 measure1_3 measure2_3 $;
cards;
1 1 1 10 5 water 85 10 water 100 103 water
2 2 2 12 5 protein 92 11 water 102 103 water
;
run;

data want;
input id approach diet time measure1 measure2 $;
cards;
1 1 1 10 5 water
1 1 1 85 10 water
1 1 1 100 103 water
2 2 2 12 5 protein
2 2 2 92 11 water
2 2 2 102 103 water
;
run;
1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

The %UNTRANSOPSE macro does exactly what you want.

https://support.sas.com/content/dam/SAS/support/en/sas-global-forum-proceedings/2018/2419-2018.pdf

 

The command shown on page 3 is analogous to your problem and ought to work.

--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

The %UNTRANSOPSE macro does exactly what you want.

https://support.sas.com/content/dam/SAS/support/en/sas-global-forum-proceedings/2018/2419-2018.pdf

 

The command shown on page 3 is analogous to your problem and ought to work.

--
Paige Miller
PeterBr
Obsidian | Level 7

Works well, thanks for sharing!

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 2 replies
  • 1164 views
  • 0 likes
  • 2 in conversation