BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Sathish_jammy
Lapis Lazuli | Level 10

Dear Experts,

 

I'm trying to update the column which already existing in another column using cross level.

In more detail. I share the sample dataset and my required output below.

 

data aaa;
input ID val1;
cards;
10 0
10 12
10 15
10 14
15 0
15 24
15 26
;

I expect my result as

IDVal1Val2
1000
10120
101512
101415
1500
15240
152624

 

Please let me know if clarification required.

Kindly suggest some ideas to resolve the task.

Thanks in advance!

 

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20
data aaa;
input ID val1;
cards;
10 0
10 12
10 15
10 14
15 0
15 24
15 26
;

data want;
    set aaa;
    by ID;
    val2=lag1(val1);
    if first.ID then val2=0;
run;

View solution in original post

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20
data aaa;
input ID val1;
cards;
10 0
10 12
10 15
10 14
15 0
15 24
15 26
;

data want;
    set aaa;
    by ID;
    val2=lag1(val1);
    if first.ID then val2=0;
run;
novinosrin
Tourmaline | Level 20

Hi @Sathish_jammy  Methinks One IFN will do,

 


data aaa;
input ID val1;
cards;
10 0
10 12
10 15
10 14
15 0
15 24
15 26
;

data want;
set aaa;
by id;
val2=ifn( first.id=0,lag(val1),0);
run;

 

 

novinosrin
Tourmaline | Level 20

Hahahahaha, You know what, Let's add to MAXIMS 🙂

 

Sir @Kurt_Bremser  Well, Let me take this opportunity to let you know that since my colleagues at CITIZENS Bank saw the huge printed version of MAXIMS sticking in my desk, everybody in our credit risk/BI started following that. One guy, by the name Connor Dahlman who was a summer intern here has become a big fan of you. 🙂 You are very popular in 1000, Lafayette Blvd 

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!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 757 views
  • 3 likes
  • 4 in conversation