BookmarkSubscribeRSS Feed
omega1983
Calcite | Level 5

I have totalled a column of numbers

ID         amt            difference

11        -250           125

11         125           125 /*only want to show this number*/

12       -250          -250

proc sql;

create table test as

select id, sum(

case when reg_num = 'w' then amt

        when reg_num = 'y' then amt

   else 0 end)as difference

from main

group by ln_no;

quit;

In the case of ID 11, I want to show the 125 difference in the second instance of the same ID.  So I want to show ID on row 2 and leave row 1 blank.  In the case of ID 12 I want to show the difference because it is the first and only instance.

1 REPLY 1
Linlin
Lapis Lazuli | Level 10

data step is much easier:

data have;

input ID         amt            difference;

cards;

11        -250           125

11         125           125

12       -250          -250

;

data want;

set have;

by id;

if not last.id then difference=.;

proc print;run;

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
  • 1 reply
  • 620 views
  • 0 likes
  • 2 in conversation