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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 2 replies
  • 677 views
  • 1 like
  • 3 in conversation