BookmarkSubscribeRSS Feed
BonnaryW
Obsidian | Level 7

Hello,

I am not an expert SAS programmer, I need help with assign value to new variables based on the "D" value  "Report_Lev1", "Report_Lev2", "Report_Lev3", and "Report_Lev4".  below is data and output:

DATA A;

ID NAME           D
1 JOE DOES |-
2 RAY DOES |-|
3 JOHN DOES |-|-
4 JANE DOES |-|-|
5 ANN DOES |-|-|-
6 DAN DOES |-|-|-
7 SCOTT DOES |-|-|
8 ME DOES  |-|-|-
9 KIM DOES |-|-|-
10 JANE ME  |-|
11 JOE ME  |-|-
12 JOHN ME  |-|-|
13 ANNE ME  |-|-|-
14 TIM ME  |-|-|-
15 ANDY ME  |-|-|
16 TRACY ME |-|-|-
17 DAVID ME |-|-|-
18 LORI ME  |-|-|-

I need help to produce the result below:


ID NAME  D Report_Lev1 Report_Lev2 Report_Lev3 Report_Lev4
1 JOE DOES |- BEGIN   
2 RAY DOES |-| RAY DOES   
3 JOHN DOES |-|- RAY DOES RAY DOES  
4 JANE DOES |-|-| RAY DOES JOHN DOES JOHN DOES 
5 ANN DOES |-|-|- RAY DOES JOHN DOES JANE DOES ANN DOES
6 DAN DOES |-|-|- RAY DOES JOHN DOES JANE DOES DAN DOES
7 SCOTT DOES |-|-| RAY DOES JOHN DOES JOHN DOES 
8 ME DOES  |-|-|- RAY DOES JOHN DOES SCOTT DOES ME DOES
9 KIM DOES |-|-|- RAY DOES JOHN DOES SCOTT DOES KIM DOES
10 JANE ME  |-| JANE ME   
11 JOE ME  |-|- JANE ME  JANE ME  
12 JOHN ME  |-|-| JANE ME  JOE ME  JOE ME 
13 ANNE ME  |-|-|- JANE ME  JOE ME  JOHN ME  ANNE ME
14 TIM ME  |-|-|- JANE ME  JOE ME  JOHN ME  TIM ME
15 ANDY ME  |-|-| JANE ME  JOE ME  JOE ME 
16 TRACY ME |-|-|- JANE ME  JOE ME  ANDY ME  TRACY ME
17 DAVID ME |-|-|- JANE ME  JOE ME  ANDY ME  DAVID ME
18 LORI ME  |-|-|- JANE ME  JOE ME  ANDY ME  LORI ME

 

 Thank you for your assistance.

 

2 REPLIES 2
tomrvincent
Rhodochrosite | Level 12

If you subtract one from ID into a new dataset

 

data b; set a; id=id-1; run;

 

 

and join a to b by id, you can then work with the next name. 

 

I'm not sure what the logic is for those symbols, but at least it's a start.

SuryaKiran
Meteorite | Level 14

The data doesn't make any sense until what logic your using to get the result. @BonnaryW

Thanks,
Suryakiran

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 2 replies
  • 1229 views
  • 1 like
  • 3 in conversation