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

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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