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-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!

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.

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