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

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

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

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

View solution in original post

4 REPLIES 4
PGStats
Opal | Level 21

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
BETO
Fluorite | Level 6

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

tthanks for your assistance

PGStats
Opal | Level 21

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
naveen_srini
Quartz | Level 8

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

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 4 replies
  • 1527 views
  • 0 likes
  • 3 in conversation