BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Mary1231
Calcite | Level 5

Hi all!

I would like to duplicate a value within 1 individual. See below for my example. 

In my example, I have multiple rows per individual, however only on 1 row contains a value for the Swabdate variable. I would like to duplicate this value to all rows within the individual.

 

How can I  do this? Thank you so much!

 

 

Example: 

Obsstudy_idswabdate
1~11001~.
2~11001~.
3~11001~.
4~11001~.
5~11001~.
6~11001~.
7~11001~.
8~11001~.
9~11001~.
10~11001~.
11~11001~.
12~11001~09/08/2017
13~11003~.
14~11003~.
15~11003~.
16~11003~.
17~11003~.
18~11003~.
19~11003~.
20~11003~.
21~11003~.
22~11003~09/18/2017
23~11005~.
1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

A datastep solution:

 

/* Assuming data is sorted by study_id */
data want;
do until(last.study_id);
    set have; by study_id;
    newdate = coalesce(newdate, swabdate);
    end;
do until(last.study_id);
    set have; by study_id;
    output;
    end;
format newdate mmddyy10.;
drop swabdate;
rename newdate=swabdate;
run;

 

Note: This pics up the first non-missing date encountered. To get the last date, use:

coalesce( swabdate, newdate).

PG

View solution in original post

2 REPLIES 2
PGStats
Opal | Level 21

A datastep solution:

 

/* Assuming data is sorted by study_id */
data want;
do until(last.study_id);
    set have; by study_id;
    newdate = coalesce(newdate, swabdate);
    end;
do until(last.study_id);
    set have; by study_id;
    output;
    end;
format newdate mmddyy10.;
drop swabdate;
rename newdate=swabdate;
run;

 

Note: This pics up the first non-missing date encountered. To get the last date, use:

coalesce( swabdate, newdate).

PG
Mary1231
Calcite | Level 5
You are the best! Thank you so much. This was the solution I was searching for.

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!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 537 views
  • 0 likes
  • 2 in conversation