BookmarkSubscribeRSS Feed
sassharp
Calcite | Level 5

ID  Regionnumber   satisfy code zipregion

1        2

2        2                     Y        1       6

3        1                      N        2       6

4        1                                          

5        3                      Y        1       6

6        3                      Y                 6

7        3                       

8        3                            

9        4                      Y         2       6

10      0                      N                  6

11       5                      Y          1      6

12       6                      Y          2      6

13       7                      N          1      6

14       0                                   1      6

 

 

 

 

Q) If Regionnumber is same for two ids, then need to copy populated ID row column values to not populated ID column values? 

 

If there is only unique Regionnumber or Regionnumber value is 0 ignore those rows. No need to change any column values.

 

 

 

Thanks in advance.

 

 

 

 

3 REPLIES 3
Ksharp
Super User
You'd better post the output you need too.




data have;
input ID  Regionnumber   satisfy $ code zipregion;
cards;
1        2 . . .
2        2                     Y        1       6
3        1                      N        2       6
4        1      . . .                                    
5        3                      Y        1       6
6        3                      Y         .         6
7        3          . . .
8        3         . . .
9        4                      Y         2       6
10      0                      N           .       6
11       5                      Y          1      6
12       6                      Y          2      6
13       7                      N          1      6
14       0                       .            1      6
;
run;
data want;
n=0;
 do until(last.Regionnumber);
  set have;
  by Regionnumber  notsorted;
  n+1;
  if not missing(satisfy) then _satisfy=satisfy;
  if not missing(code) then _code=code;
  if not missing(zipregion) then _zipregion=zipregion;
 end;
 _Regionnumber =Regionnumber  ;
 do until(last.Regionnumber);
  set have;
  by Regionnumber  notsorted;
  if n gt 1 and _Regionnumber ne 0 then do;
   satisfy=_satisfy;
   code=_code;
   zipregion=_zipregion;
   output;
  end;
  else output;
 end;
 drop _: n;
run;
 



sassharp
Calcite | Level 5

Output needed

 

ID  Regionnumber   satisfy code zipregion

1        2                     Y        1       6

2        2                     Y        1       6

3        1                     N        2       6

4        1                     N        2       6                           

5        3                      Y        1       6

6        3                      Y        1       6

7        3                      Y        1       6

8        3                      Y         1      6

9        4                      Y         2       6

10      0                      N                  6

11       5                      Y          1      6

12       6                      Y          2      6

13       7                      N          1      6

14       0                                   1      6

sassharp
Calcite | Level 5
If there are no duplicates for regionnumber(that means leave unique regionnumber without any column value changes) or regionnumber is 0 no changes to column values.

if regionnumber exists more than once need to copy all column values of regionnumber populated ones with not populated regionnumber.

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 1078 views
  • 0 likes
  • 2 in conversation