## Proc transpose question

Solved
Regular Contributor
Posts: 240

# Proc transpose question

hi

i have a table that looks like this

number.   Value.         Balance

1.                1.                1

1.                  2.                5

1.                   3.                10

1.                    4.                20

I Would like it to look like this

number  Balance.   1.       2.     3.   4.

1               36           1.        5.    10  20

thanks again

Accepted Solutions
Solution
‎03-16-2015 09:52 PM
Posts: 5,529

## Re: Proc transpose question

Like this :

data have;

input number Value Balance;

datalines;

1. 1. 1

1. 2. 5

1. 3. 10

1. 4. 20

;

proc transpose data=have out=temp(drop=_ prefix=v_;

by number;

id value; idlabel value;

var balance;

run;

data want;

length number balance 8;

set temp;

balance = sum(of v_;

run;

PG

PG

All Replies
Solution
‎03-16-2015 09:52 PM
Posts: 5,529

## Re: Proc transpose question

Like this :

data have;

input number Value Balance;

datalines;

1. 1. 1

1. 2. 5

1. 3. 10

1. 4. 20

;

proc transpose data=have out=temp(drop=_ prefix=v_;

by number;

id value; idlabel value;

var balance;

run;

data want;

length number balance 8;

set temp;

balance = sum(of v_;

run;

PG

PG
Regular Contributor
Posts: 240

## Re: Proc transpose question

PGSTATS

i using your example I tweaked it to fit my code

proc sort data = part2;

by number;

run;

proc transpose data  = part2 out temp(drop=_ prefix = v_;

by number ;

id facevalue; idlabel facevalue;

var ebal;

run;

i get this error message

error The id value "v_1_00" occurs twice in the same by group.

note the above message was for the following  by group number = 4407

it happens six more time same error message different number

Posts: 5,529

## Re: Proc transpose question

It could be that

1) You have duplicate values for facevalue in some number groups or

2) The format associated with facevalue makes certain values look the same when creating new column names. I.e. 1.001 and 1.002 with format 5.2 will both generate the same variable name v_1_00

Make sure that all facevalue values are unique within number groups and that they also look unique when formatted.

PG

PG
Frequent Contributor
Posts: 115

## Re: Proc transpose question

data have;

input number Value Balance;

datalines;

1. 1. 1

1. 2. 5

1. 3. 10

1. 4. 20

;

data want;
set have(rename=(balance=b)) end=last;
array v(4);
retain v;
v(_n_)=b;

if last then
do;
balance=sum(of v{*});
output;
end;

drop value B;
run;

Regards,

Naveen Srinivasan

L&T Infotech

🔒 This topic is solved and locked.