Help using Base SAS procedures

Proc transpose question

Accepted Solution Solved
Reply
Regular Contributor
Posts: 240
Accepted Solution

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
Respected Advisor
Posts: 4,649

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=_Smiley Happy prefix=v_;

by number;

id value; idlabel value;

var balance;

run;

data want;

length number balance 8;

set temp;

balance = sum(of v_Smiley Happy;

run;

PG

PG

View solution in original post


All Replies
Solution
‎03-16-2015 09:52 PM
Respected Advisor
Posts: 4,649

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=_Smiley Happy prefix=v_;

by number;

id value; idlabel value;

var balance;

run;

data want;

length number balance 8;

set temp;

balance = sum(of v_Smiley Happy;

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=_Smiley Happy 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

tthanks for your assistance

Respected Advisor
Posts: 4,649

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.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 297 views
  • 0 likes
  • 3 in conversation