DATA Step, Macro, Functions and more

lag addition

Accepted Solution Solved
Reply
Contributor
Posts: 30
Accepted Solution

lag addition

Can you please help with following?

data a;
input var1 $;
datalines;
a
b
c
d
e
;
run;

what I need is:

var1var2
aa
ba-b
ca-b-c
da-b-c-d
ea-b-c-d-e
 

 


Accepted Solutions
Solution
‎11-30-2017 12:58 PM
Super User
Posts: 24,004

Re: lag addition

cat = catx('-',lag(var1),var1) ;

 

That doesn't make sense, you want to add the new variable, not the previous variable1 and current variable.

 

cat = catx('-',cat,var1) ;

 

View solution in original post


All Replies
Super User
Posts: 24,004

Re: lag addition

RETAIN + CATX. 

 

 

Contributor
Posts: 30

Re: lag addition

data b ;
    length cat $200 ;
set a ;
retain cat;
cat = catx('-',lag(var1),var1) ;
run ;

This is what I have but not getting results i want.
Solution
‎11-30-2017 12:58 PM
Super User
Posts: 24,004

Re: lag addition

cat = catx('-',lag(var1),var1) ;

 

That doesn't make sense, you want to add the new variable, not the previous variable1 and current variable.

 

cat = catx('-',cat,var1) ;

 

Contributor
Posts: 30

Re: lag addition

Thank you @Reeza

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 222 views
  • 0 likes
  • 2 in conversation