Can any one help me?

Reply
Contributor
Posts: 26

Can any one help me?

Dear All,

I had following dataset

A  B

a  1

b  2

I need to convert the data set into following dataset in single step

A  B

a  1

b  2

k  3

k is  combination  of a and b. 3 is sum of 1+2

Contributor
Posts: 62

Re: Can any one help me?

Posted in reply to sravanpathu

Why do you want add them up there?

It is better to put summary statistics in another data set.( using proc means)

But, OK, the following code is what you want:


proc report data = test out=test_out nowd;

   col A B ;

   rbreak after / summarize;

run;



For details, see

Smiley Happy




Super Contributor
Posts: 1,636

Re: Can any one help me?

Posted in reply to sravanpathu

data have;

input A$ B;

cards;

a 1

b 2

;

data want;

  set have end=last;

  output;

  t+b;

  if last then do;

  b=t;a='k';

  output;end;

  drop t;

  proc print;run;

Contributor
Posts: 26

Re: Can any one help me?

Thanks alot ma'am

Can we do same in PROC SQL

Super Contributor
Posts: 1,636

Re: Can any one help me?

Posted in reply to sravanpathu

You are welcome!

Proc sql also worksSmiley Happy:

data have;

input A$ B;

cards;

a 1

b 2

;

proc sql;

   create table want as

     select * from have

  union

  select * from (select 'k' as a1,sum(b) as b1 from have);

  quit;

proc print;run;

Respected Advisor
Posts: 4,923

Re: Can any one help me?

Posted in reply to sravanpathu

I'm curious, in what way is 'k' a combination of 'a' and 'b'?

PG

PG
Ask a Question
Discussion stats
  • 5 replies
  • 246 views
  • 0 likes
  • 4 in conversation