DATA Step, Macro, Functions and more

How can we do with retain statement creating sequence number?

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 86
Accepted Solution

How can we do with retain statement creating sequence number?

In the below code I have created sequence number using first and last name in the sashelp.class I have distinct name so we get every record with 1 value in seq variable. Same i need in retain concept without using first and last.name.


data a; set sashelp.class; run; data a1; set a; by name; if first.name then seq=1; else seq+1; run;

 


Accepted Solutions
Solution
‎01-14-2018 06:48 PM
PROC Star
Posts: 1,784

Re: How can we do with retain statement creating sequence number?

Posted in reply to rajeshalwayswel

Are you after the same results as you did, meaning all 1s

 

data a;
set sashelp.class;
run;

data a1;
set a;
retain seq 1;
if lag(name) eq name then seq+1;
run;

View solution in original post


All Replies
Solution
‎01-14-2018 06:48 PM
PROC Star
Posts: 1,784

Re: How can we do with retain statement creating sequence number?

Posted in reply to rajeshalwayswel

Are you after the same results as you did, meaning all 1s

 

data a;
set sashelp.class;
run;

data a1;
set a;
retain seq 1;
if lag(name) eq name then seq+1;
run;
☑ This topic is solved.

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

Discussion stats
  • 1 reply
  • 141 views
  • 0 likes
  • 2 in conversation