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]

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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