BookmarkSubscribeRSS Feed
sravanpathu
Calcite | Level 5

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

5 REPLIES 5
MohammadFayaz
Calcite | Level 5

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




Linlin
Lapis Lazuli | Level 10

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;

sravanpathu
Calcite | Level 5

Thanks alot ma'am

Can we do same in PROC SQL

Linlin
Lapis Lazuli | Level 10

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;

PGStats
Opal | Level 21

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

PG

PG

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 673 views
  • 0 likes
  • 4 in conversation