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

Hi,

I am far from an expert SAS coder, but I am getting a message that doesn't make sense when I try to transpose some variables. It is claiming that by ID value occurs twice in the same BY group, but (1) it doesn't do this for the other variable using the same ID value (participant_ID) and BY value (VISIT_number). There do not seem to be any duplicates and when I look at any one variable for which I am unable to transpose, I don't see any problems as I scan through. Could someone help me understand why this is happening and what I need to do?

Below is the data and code for one of the variables

 

Data longnew1;
input Participant_Id	Visit_Number	Total_Saturated_Fatty_Acids__SFA;
datalines;
10236655	1	21.628
10236655	2	30.52
10237250	1	19.211
10237250	2	31.091
10237250	3	28.711
10237401	1	5.462
10237556	1	12.655
10237556	2	12.185
10237556	3	4.017
10237706	1	11.324
10238450	1	23.372
10238450	2	13.916
10238757	1	28.543
10238757	2	9.911
10238757	3	8.629
10239805	1	44.15
10239805	2	20.799
10239805	3	28.687
10240253	1	9.469
10240253	2	8.977
11250151	1	41.036
11250151	2	24.169
11250151	3	11.819
11250455	1	19.415
11250455	2	31.002
11250455	3	18.034
11250603	1	12.709
11250603	2	16.125
11250603	3	20.107
11250751	1	12.471
11250903	1	20.054
11250903	2	5.806
11251056	1	12.5
11251056	2	34.56
11251056	3	23.706
13295155	1	50.874
13295155	2	4.845
13295155	3	13.822
13295458	1	21.113
13295458	2	29.268
13295458	3	28.507
13295753	1	28.293
13295903	1	17.979
13295903	2	17.132
13295903	3	8.618
13296350	1	5.883
13296350	2	15.366
13296350	3	14.183
13296804	1	38.804
13296804	2	16.999
16340457	1	20.761
16340457	2	9.152
16340753	1	15.721
16340753	2	30.064
16340753	3	13.075
16341205	1	32.078
16341205	2	15.617
16341353	1	24.141
16341353	2	12.722
16341653	1	43.871
16341653	2	13.761
16341653	3	10.047
16341802	1	23.627
17355156	1	25.635
17355156	2	21.585
17355156	3	20.3
17355600	1	23.423
17355600	2	25.285
17355901	1	16.863
17355901	2	24.389
17355901	3	23.742
17356050	1	5.312
17357100	1	21.511
17357100	2	8.419
17357100	3	16.564
19385302	1	21.384
19385302	2	21.252
19385905	1	52.782
19385905	2	14.079
19386204	1	25.737
19386204	2	44.51
19386204	3	22.578
19386357	1	49.11
19386357	2	13.278
19386357	3	10.531
19386506	1	20.799
19386950	1	28.868
19386950	2	31.945
19386950	3	16.967
19387251	1	14.874
19387251	2	24.792
19387251	3	8.858
19387851	1	31.998
19387851	2	46.478
19387851	3	38.807
19388004	1	12.038
19388004	2	56.342
19388155	1	26.069
19388155	2	6.103
19388155	3	41.472
19388458	1	2.819
19388458	2	3.809
19388605	1	49.202
19388605	2	17.089
19388605	3	24.041
19388756	1	9.878
19388756	2	16.992
19388756	3	3.238
19389205	1	33.86
19389205	2	11.15
19389205	3	19.562
19389352	1	21.672
19389352	2	41.865
19389352	3	18.09
19389505	1	20.319
19389505	2	11.666
19389505	3	20.271
20401204	1	12.071
20401204	2	8.202
20401204	3	18.964
20401356	1	13.681
20401505	1	38.9
20401505	2	16.711
20401505	3	22.722
20401650	1	25.283
20401801	1	34.801
20401801	2	8.187
20401801	3	20.741
20401952	1	13.832
20401952	2	29.47
20401952	3	15.591
20402101	1	29.274
20402251	1	28.726
20402402	1	7.68
20402402	2	6.951
20402402	3	5.596
20402556	1	19.883
20403006	1	12.411
20403006	2	24.974
20403006	3	15.953
20403300	1	12.306
20403300	2	6.592
20403455	1	16.372
20403602	1	12.74
20403602	2	17.115
20403602	3	27.971
21415152	1	5.348
21415152	2	18.445
21415152	3	1.76
21415755	1	27.213
21415755	2	19.171
21415908	1	30.014
21415908	2	28.578
21415908	3	23.099
21416058	1	37.647
21416058	2	28.078
21416354	1	22.833
21416354	2	21.004
21416354	3	12.119
21416650	1	8.519
21416650	2	12.09
21416955	1	11.43
21416955	2	15.763
21416955	3	13.331
22430154	1	34.252
22430154	2	20.169
22430154	3	19.528
22430607	1	27.422
22431058	1	14.998
22431058	2	14.425
22431058	3	10.699
22431205	1	30.105
22431205	2	42.789
22431205	3	38.617
22431356	1	8.626
22431356	2	7.921
22431356	3	32.807
22431506	1	12.726
22431506	2	20.17
22431506	3	15.131
22431958	1	20.409
22431958	2	19.147
22431958	3	23.846
24460158	1	60.264
24460158	2	15.685
24460306	1	18.394
24460306	2	16.807
24460906	1	25.502
24460906	2	7.989
24460906	3	29.475
24461050	1	18.178
28520451	1	8.737
28520451	2	11.769
28520451	3	14.578
28521057	1	40.784
28521057	2	10.618
28521207	1	35.404
28521500	1	17.549
28521500	2	14.861
28521500	3	18.437
29536050	1	4.916
29536050	2	15.129
29536955	1	36.43
29536955	2	12.577
29536955	3	24.309
29537556	1	13.654
30550152	1	19.479
31566058	1	14.026
31566058	2	15.57
31566058	3	7.047
31566506	1	63.486
32580156	1	17.775
32580156	2	3.555
32581054	1	17.148
32581054	2	37.36
32581505	1	23.756
32581505	2	12.295
32581505	3	35.206
32581658	1	47.577
32581658	2	17.082
32581658	3	14.935
32581806	1	31.179
32581806	2	17.079
32581955	1	14.155
32581955	2	9.901
32581955	3	11.663
32582104	1	38.991
32582104	2	22.91
32582104	3	25.37
32582256	1	39.021
32582550	1	36.11
33596504	1	9.649
33596504	2	12.778
33596654	1	26.53
33596654	2	28.36
33596654	3	28.949
33596801	1	35.429
33597100	1	25.014
33597100	2	10.696
33597100	3	6.638
33597400	1	8.777
33597400	2	3.048
33597400	3	7.418
33597552	1	26.96
33597552	2	38.172
33597552	3	10.847
33597702	1	21.558
33597702	2	24.174
33597702	3	7.87
33597858	1	32.939
33597858	2	21.997
33598154	1	10.187
33598154	2	21.206
33598154	3	21.934
33598300	1	15.42
33598300	2	22.617
33598300	3	63.753
33598608	1	11.04
33598608	2	14.616
33598608	3	8.199
34610155	1	24.789
34610155	2	5.22
34610455	1	43.654
34610455	2	17.756
34610455	3	25.831
34610600	1	22.467
34610600	2	36.698
34610600	3	20.072
34610756	1	20.638
34610756	2	25.789
34610907	1	37.848
34610907	2	24.156
34611356	1	16.76
34611506	1	22.819
34611506	2	14.729
35625308	1	21.136
35625308	2	29.989
35625308	3	26.774
35625451	1	12.695
35625451	2	10.669
35625451	3	13.909
35625904	1	10.741
35625904	2	31.55
35625904	3	24.913
35626057	1	54.093
35626057	2	40.73
35626057	3	27.348
35626957	1	22.156
35626957	2	18.223
35626957	3	23.116
35627400	1	53.208
35627400	2	14.295
35627400	3	29.347
35627558	1	35.584
35627857	1	8.474
35627857	2	18.69
35627857	3	8.431
35628005	1	23.791
35628005	2	22.841
37655454	1	17.684
37655454	2	9.295
37655454	3	7.838
37655603	1	19.946
37655603	2	15.315
37655603	3	18.987
37655908	1	46.588
37655908	2	20.613
37655908	3	19.867
37656050	1	13.596
37656050	2	18.672
37656050	3	25.269
37656204	1	19.067
37656204	2	13.298
37656204	3	14.326
37656358	1	18.426
37656358	2	38.061
37656358	3	59.605
37656650	1	22.754
37656650	2	13.824
37656650	3	13.215
37656803	1	36.171
37656803	2	33.818
37656803	3	36.074
37657106	1	30.164
37657106	2	22.712
37657106	3	18.579
37657256	1	6.462
38670601	1	14.73
38671804	1	29.763
40700300	1	13.703
40700300	2	9.65
40700300	3	15.104
42730307	1	20.678
42730757	1	19.308
42730757	2	15.616
42730907	1	11.602
42730907	2	5.268
42730907	3	14.174
42731352	1	11.048
42731352	2	22.77
42731352	3	4.947
42731802	1	10.226
42731802	2	3.804
42732106	1	27.155
42732106	2	21.959
42732106	3	30.026
42732253	1	29.525
42732253	2	19.149
43746654	1	22.716
43746654	2	24.27
43746654	3	22.898
43747554	1	4.823
43747554	2	46.993
43748157	1	7.91
43748157	2	21.31
43748157	3	92.216
43754757	1	44.415
43754905	1	10.122
43754905	2	15.195
43755202	1	23.557
43755202	2	17.197
43755202	3	10.117
43755507	1	6.442
43755507	2	12.917
43755507	3	10.685
43755653	1	14.826
43755653	2	11.877
43755653	3	7.496
43755802	1	19.756
43755802	2	10.271
43755954	1	24.671
43755954	2	29.132
43755954	3	31.391
43756108	1	23.682
43756108	2	15.184
43756108	3	19.62
43756252	1	35.687
43756402	1	31.063
43756555	1	32.794
43756555	2	51.91
43756555	3	31.095
45775753	1	29.578
45775753	2	22.345
45776204	1	41.893
45776204	2	21.097
45777104	1	36.684
45777258	1	19.403
45777258	2	22.717
45777258	3	15.659
45777700	1	19.957
45777700	2	14.102
45778750	1	17.351
45778750	2	11.222
45778750	3	19.746
46790455	1	16.305
46790455	2	8.73
46790601	1	3.879
46790601	2	12.812
46790751	1	30.88
46790751	2	12.095
46790903	1	16.882
46790903	2	20.759
46791054	1	6.765
46791054	2	4.712
46791200	1	9.003
46791200	2	4.706
46791200	3	0.484
46791506	1	9.245
46791506	2	30.962
46791506	3	29.839
46791655	1	14.853
46791655	2	17.846
46791655	3	16.788
46791806	1	14.935
46791951	1	19.674
46791951	2	14.401
46791951	3	23.3
46792102	1	9.895
46792408	1	13.002
46792408	2	22.332
46792408	3	47.377
46792552	1	31.29
46792552	2	24.012
46792552	3	15.795
47805900	1	17.138
47805900	2	13.968
47806804	1	39.471
47806804	2	23.152
47806804	3	29.021
48820303	1	9.686
48820303	2	14.165
52115152	1	10.508
52115152	2	24.009
52115152	3	10.405
52115301	1	28.367
52115301	2	38.151
52115602	1	31.926
52115602	2	44.189
52115602	3	35.596
52115756	1	11.13
52115756	2	31.23
52115756	3	18.877
52115905	1	11.096
54146051	1	22.189
54146051	2	15.44
54146507	1	35.763
54146507	2	20.373
54146507	3	26.305
;
run;
proc transpose data=longnew1 out=wideNew1 prefix=Total_Saturated_Fatty_Acids__SFA;
   by Participant_id;
   id Visit_Number;
   var Total_Saturated_Fatty_Acids__SFA;
run;

 

Log
7238 proc transpose data=longnew1 out=wideNew1 prefix=Total_Saturated_Fatty_Acids__SFA;
7239 by Participant_id;
7240 id Visit_Number;
7241 var Total_Saturated_Fatty_Acids__SFA;
7242 run;

ERROR: The ID value "Total_Saturated_Fatty_Acids__SFA" occurs twice in the same BY group.
NOTE: The above message was for the following BY group:
Participant_Id=10236655
ERROR: The ID value "Total_Saturated_Fatty_Acids__SFA" occurs twice in the same BY group.
ERROR: The ID value "Total_Saturated_Fatty_Acids__SFA" occurs twice in the same BY group.
NOTE: The above message was for the following BY group:
Participant_Id=10237250
ERROR: The ID value "Total_Saturated_Fatty_Acids__SFA" occurs twice in the same BY group.
ERROR: The ID value "Total_Saturated_Fatty_Acids__SFA" occurs twice in the same BY group.
NOTE: The above message was for the following BY group:
Participant_Id=10237556
ERROR: The ID value "Total_Saturated_Fatty_Acids__SFA" occurs twice in the same BY group.
NOTE: The above message was for the following BY group:
Participant_Id=10238450
ERROR: The ID value "Total_Saturated_Fatty_Acids__SFA" occurs twice in the same BY group.
ERROR: The ID value "Total_Saturated_Fatty_Acids__SFA" occurs twice in the same BY group.
NOTE: The above message was for the following BY group:
Participant_Id=10238757
ERROR: The ID value "Total_Saturated_Fatty_Acids__SFA" occurs twice in the same BY group.
ERROR: The ID value "Total_Saturated_Fatty_Acids__SFA" occurs twice in the same BY group.
NOTE: The above message was for the following BY group:
Participant_Id=10239805
ERROR: The ID value "Total_Saturated_Fatty_Acids__SFA" occurs twice in the same BY group.
NOTE: The above message was for the following BY group:
Participant_Id=10240253
ERROR: The ID value "Total_Saturated_Fatty_Acids__SFA" occurs twice in the same BY group.
ERROR: The ID value "Total_Saturated_Fatty_Acids__SFA" occurs twice in the same BY group.
NOTE: The above message was for the following BY group:
Participant_Id=11250151
ERROR: The ID value "Total_Saturated_Fatty_Acids__SFA" occurs twice in the same BY group.
ERROR: The ID value "Total_Saturated_Fatty_Acids__SFA" occurs twice in the same BY group.
NOTE: The above message was for the following BY group:
Participant_Id=11250455
ERROR: The ID value "Total_Saturated_Fatty_Acids__SFA" occurs twice in the same BY group.
ERROR: The ID value "Total_Saturated_Fatty_Acids__SFA" occurs twice in the same BY group.
ERROR: Too many bad BY groups.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: There were 29 observations read from the data set WORK.LONGNEW1.
WARNING: The data set WORK.WIDENEW1 may be incomplete. When this step was stopped there were 0
observations and 0 variables.
WARNING: Data set WORK.WIDENEW1 was not replaced because this step was stopped.
NOTE: PROCEDURE TRANSPOSE used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds

 

Any help would be appreciated.

Thanks,

Liam 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
Your prefix is 32 characters so you have no room for your ID variable.
Shorten your PREFIX length - remember the total variable length once you include the ID variable should be less than 32 characters.

proc transpose data=longnew1 out=wideNew1 prefix=Total_Saturated_Fatty_Acids__SFA;
by Participant_id;
id Visit_Number;
var Total_Saturated_Fatty_Acids__SFA;
run;

Total_Saturated_Fatty_Acids__SFA => 32 characters in length.

View solution in original post

2 REPLIES 2
Reeza
Super User
Your prefix is 32 characters so you have no room for your ID variable.
Shorten your PREFIX length - remember the total variable length once you include the ID variable should be less than 32 characters.

proc transpose data=longnew1 out=wideNew1 prefix=Total_Saturated_Fatty_Acids__SFA;
by Participant_id;
id Visit_Number;
var Total_Saturated_Fatty_Acids__SFA;
run;

Total_Saturated_Fatty_Acids__SFA => 32 characters in length.
wmckvr
Calcite | Level 5

Thank you! I would never have guessed such a simple answer.

 

Liam

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