Hi, I am working with a dataset that collected some body measurements., I would like to duplicate the observation on the same row to do a pre-treatment and post-treatment analysis. For example, having 1.2 again for record one. This a large dataset and doing this by hand or if-then statements is near to impossible.
record | measure A |
1 | 1.2 |
1 | . |
2 | 1.3 |
2 | 1.3 |
3 | . |
3 | . |
data have;
input record measure_A;
cards;
1 1.2
1 .
2 1.3
2 1.3
3 .
3 .
;
data want;
update have(obs=0) have;
by record;
output;
run;
What exactly do you want as output?
1.3 filled down? What about Record 3s? Are both missing there? Should they stay missing or take the previous value?
Please show what you start with and what you want as output.
@emma19901 wrote:
Hi, I am working with a dataset that collected some body measurements., I would like to duplicate the observation on the same row to do a pre-treatment and post-treatment analysis. For example, having 1.2 again for record one. This a large dataset and doing this by hand or if-then statements is near to impossible.
record measure A 1 1.2 1 . 2 1.3 2 1.3 3 . 3 .
After duplicating the values by record the missing data will be deleted., I can not do it before because I will lose the records of interest.
It's not quite clear what you're trying to do. You can use OUTPUT to control the writing of records to an output step. So assuming you want to duplicate every record without a measure_A value, this has two output statements, which gives you two records.
Note the output statement causes implicit outputs to stop, so you have to explicitly specify when you want a record written to the data set.
data want;
set have;
if not missing(measure_A) then do;
output;output;
end;
run;
@emma19901 wrote:
After duplicating the values by record the missing data will be deleted., I can not do it before because I will lose the records of interest.
Is this what you are looking for ?
data want;
set have;
by record;
retain measure_a_;
if first.record then measure_a_=measure_a;
if missing(measure_a) then measure_a=measure_a_;
drop measure_a_;
run;
Yes, but is not working
data have;
input record measure_A;
cards;
1 1.2
1 .
2 1.3
2 1.3
3 .
3 .
;
data want;
update have(obs=0) have;
by record;
if measure_a>. then output;
run;
Help us help you. Please show the layout of the desired result data.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.