BookmarkSubscribeRSS Feed
emma19901
Calcite | Level 5

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. 

 

recordmeasure A
11.2
1.
21.3
21.3
3.
3.
9 REPLIES 9
novinosrin
Tourmaline | Level 20
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;
 

 

Reeza
Super User

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 .

 

emma19901
Calcite | Level 5

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.

Reeza
Super User

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.


 

r_behata
Barite | Level 11

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;
emma19901
Calcite | Level 5

Yes, but is not working

novinosrin
Tourmaline | Level 20

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;
r_behata
Barite | Level 11
How should your expected output look like ?
mkeintz
PROC Star

@emma19901

 

Help us help you.  Please show the layout of the desired result data.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

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.

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
  • 9 replies
  • 1059 views
  • 0 likes
  • 5 in conversation