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

Hello

I have a data set called aaa and by using proc transpose I want to get another data set called bbb.

The result of bbb data set is not as I want because under column "pet" I expect to have only 3 rows: dog,cat,fish

Data aaa;
input pet_owner $ pet $  poulation;
cards;
Dave dog 2
Dave cat 1 
Yulia dog 2
Yulia cat 2
Joe fish 7
Joe dog 1
Joe cat 1
;
run;


proc transpose data=aaa name=Metric out=bbb;
id pet_owner;
by pet NOTSORTED;
var poulation;
run;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
andreas_lds
Jade | Level 19

The result you get is 100% correct when using "notsorted", the docs say: "If observations with the same values for the BY variables are not contiguous, then the procedure treats each contiguous set as a separate BY group."

 

You will have to sort dataset aaa to get what you want.

View solution in original post

2 REPLIES 2
andreas_lds
Jade | Level 19

The result you get is 100% correct when using "notsorted", the docs say: "If observations with the same values for the BY variables are not contiguous, then the procedure treats each contiguous set as a separate BY group."

 

You will have to sort dataset aaa to get what you want.

Astounding
PROC Star
Sort the data by PET, and remove the word NOTSORTED.

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
  • 771 views
  • 2 likes
  • 3 in conversation