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 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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