BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
twildone
Pyrite | Level 9

Hi....I am trying to correct the entries in Dept for the same ID by changing them to the entry that is entered for Dept when Section = s1 except for when Dept=a4. Any suggestions? Thanks

 

data one;
input ID Dept$ Section$ credit;
datalines;
1 a1 s1    
1 a1 s2 0.5
1 a2 s3 1.0
1 a2 s4 1.0
1 a4 s5 1.0
1 a4 s6      
2 a1 s3 1.0
2 a1 s2 0.5
2 a2 s1    
2 a3 s4 1.0
2 a4 s5 1.0
2 a1 s5 0.5
2 a1 s5 1.0
2 a1 s6 1.0
2 a3 s6    
2 a2 s6 1.0
3 a4 s5 0.5
3 a2 s5    
3 a2 s5 1.0
3 a1 s1    
3 a1 s2 1.0
3 a1 s3 1.0
;
run;

 Want:

 

 

data want;

1 a1 s1    

1 a1 s2 0.5

1 a1 s3 1.0

1 a1 s4 1.0

1 a4 s5 1.0

1 a4 s6     

2 a2 s3 1.0

2 a2 s2 0.5

2 a2 s1  

2 a2 s4 1.0

2 a4 s5 1.0

2 a2 s5 0.5

2 a2 s5 1.0

2 a2 s6 1.0

2 a2 s6  

2 a2 s6 1.0

3 a4 s5 0.5

3 a1 s5    

3 a1 s5 1.0

3 a1 s1  

3 a1 s2 1.0

3 a1 s3 1.0

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

One way:


data WANT; 
  merge ONE ONE(keep=ID DEPT SECTION rename=(DEPT=D SECTION=S) where=(S='s1'));
  by ID;
  if DEPT ne 'a4' then DEPT=D;
  drop D S;
run;

 [Edited to add a4 exception]

View solution in original post

1 REPLY 1
ChrisNZ
Tourmaline | Level 20

One way:


data WANT; 
  merge ONE ONE(keep=ID DEPT SECTION rename=(DEPT=D SECTION=S) where=(S='s1'));
  by ID;
  if DEPT ne 'a4' then DEPT=D;
  drop D S;
run;

 [Edited to add a4 exception]

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1 reply
  • 733 views
  • 0 likes
  • 2 in conversation