BookmarkSubscribeRSS Feed
RandyStan
Fluorite | Level 6

Dear All

 

My Data set looks like this:

 

ID                VAR_A

1                    A

1                   A

1                   A

2                   .

2                   A

2                   A

3                   .

3                   .

3                   .

4                  C

4                  C

5                  

5                   D

5                   

 

 

I want it to look like this:

 

ID                VAR_A             Correct_VAR_A

1                    A                           A

1                   A                            A

1                   A                            A

2                   .                             A

2                   A                           A

2                   A                           A

3                   .                             

3                   .

3                   .

4                  C                         C

4                  C                         C

5                                             D

5                   D                        D

5                                            D

 

Please help

 

Randy

 

 

 

 

5 REPLIES 5
Reeza
Super User
If you can always guarantee that you only have one value of VAR_A per ID use SQL.

proc sql;
create table want as select *, max(var_a) as correct_var_a from have group by ID order by ID;
quit;
novinosrin
Tourmaline | Level 20

Just one unique Var_A values per ID? Just can't think of a scenario

 

Anyway-


data have;
input ID                VAR_A $;
cards;
1                    A

1                   A

1                   A

2                   .

2                   A

2                   A

3                   .

3                   .

3                   .

4                  C

4                  C

5                  .

5                   D

5                   .
;

data want;
 merge have(drop=var_a) have(where=(var_A>' '));
 by id;
run;
RandyStan
Fluorite | Level 6

Yes there is only one unique value per ID

 

I looked up this solution.  But it is much more complicated than the one posted by novinosrin

 

data have;
input ID    status;
cards;
1        . 
1        .
1        . 
1        5
2        .
2        .
2        6
;
run;

data want;
 do until(not missing(status) or last.id );
  set have;
  by id;  
 end;
 temp=status;
 do until(not missing(status) or last.id );
  set have;
  by id;
  _status=temp;output;
 end;
 drop temp status;
run;

 

novinosrin
Tourmaline | Level 20

I honestly can't see a need for a double DOW loop i.e. assuming I understood the requirement. Am i missing something

RandyStan
Fluorite | Level 6

Novinosrin:

  I agree with your last statement.  I shall test your code later tonight.

  Thanks so much.

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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
  • 5 replies
  • 864 views
  • 3 likes
  • 3 in conversation