DATA Step, Macro, Functions and more

how to create a copy of first observation of each subject in sas?

Accepted Solution Solved
Reply
Frequent Contributor
Frequent Contributor
Posts: 105
Accepted Solution

how to create a copy of first observation of each subject in sas?

I have a dataset with 10 observations per subject. I want to create  a copy of the first observation  so that  new datset will contain 11 observations per subject.

 

Thanks


Accepted Solutions
Solution
‎07-29-2016 10:34 AM
Super User
Super User
Posts: 7,997

Re: how to create a copy of first observation of each subject in sas?

Thats just controlling the output statement:

data want;   /* assumes sorted!! */
  set have;
  by subject;
  if first.subject then do;
    output;
    output;
  end;
  else output;
run;

The above will output two rows if first.subject.  Note needs to be sorted by subject and then the rows in the order you want.

View solution in original post


All Replies
Solution
‎07-29-2016 10:34 AM
Super User
Super User
Posts: 7,997

Re: how to create a copy of first observation of each subject in sas?

Thats just controlling the output statement:

data want;   /* assumes sorted!! */
  set have;
  by subject;
  if first.subject then do;
    output;
    output;
  end;
  else output;
run;

The above will output two rows if first.subject.  Note needs to be sorted by subject and then the rows in the order you want.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 1 reply
  • 328 views
  • 1 like
  • 2 in conversation