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]

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 1 reply
  • 490 views
  • 0 likes
  • 2 in conversation