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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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