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

Hi,

 

I have data arranged in the following way:

 

IDFoodintake
1food132
1food212
1food369
2food122
2food278
2food356

 

Using the PROC TRANSPOSE procedure, I want to structure it in this way:

IDfood1food2food3
1321269
2227856

 

I have used the following code to restructure:

 

proc transpose data=have out=want;

id food;

var intake;

by ID;

run;

 

However, I repeatedly get the following error message, for each food:

"The ID value "food1" occurs twice in the same BY group."

 

The output seems OK after some random checks, so I wonder why I get this error message. Does it have to do with the length of the character variables (the actual strings are longer than the length of 'food1' etc).

 

Hope someone can help me out!

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
Then your data must have something like :



ID	Food	intake
1	food1	32
1	food1	22
1	food1	12
1	food2	12
1	food3	69


use PROC SORT nodupkey; by id food ;run; to have unique Key value.

View solution in original post

3 REPLIES 3
Ksharp
Super User
Then your data must have something like :



ID	Food	intake
1	food1	32
1	food1	22
1	food1	12
1	food2	12
1	food3	69


use PROC SORT nodupkey; by id food ;run; to have unique Key value.
Marjolein
Obsidian | Level 7

It worked, thanks a lot!

art297
Opal | Level 21

If you have more than one record per ID/food combination, I would first ask why. While @Ksharp showed you a way to eliminate duplicate ID/food combinations, possibly you need to run proc summary first to sum the intake values for each ID/food combination.

 

Art, CEO, AnalystFinder.com

 

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 2998 views
  • 1 like
  • 3 in conversation