BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
michtka
Fluorite | Level 6

Hi everyone, I got the next dataset with three variables, sorting by subjid and dpfdate:

        txt

    1 SLOW INCRE
    2 ROUTINE DO
    3 ROUTINE DO
    4 ROUTINE DO
    5 ROUTINE DO
    6 ROUTINE DO
    7 ROUTINE DO
    8 ROUTINE DO
    9 ROUTINE DO
  10 ROUTINE DO
  11 ROUTINE DO
  12 ROUTINE DO
  13 ROUTINE DO
  14 ROUTINE DO
  15 ROUTINE DO
  16 ROUTINE DO
  17 ROUTINE DO
  18 ROUTINE DO
  19 ROUTINE DO

Obs  DPFDATE    SUBJID

    1 13DEC2006    10051001
    2 14DEC2006    10051001
    3 15DEC2006    10051001
    4 16DEC2006    10051001
    5 17DEC2006    10051001
    6 18DEC2006    10051001
    7 19DEC2006    10051001
    8 20DEC2006    10051001
    9 21DEC2006    10051001
  10 22DEC2006    10051001
  11 23DEC2006    10051001
  12 24DEC2006    10051001
  13 25DEC2006    10051001
  14 26DEC2006    10051001
  15 27DEC2006    10051001
  16 28DEC2006    10051001
  17 29DEC2006    10051001
  18 30DEC2006    10051001
  19 31DEC2006    10051001

I would like tocreate a dataset something like:

1 slow increase  13dec2006  10051001

2routine do          14dec2006  10051001

3routine do          31dec2006  10051001

I mean: sorting out by subjid and dpfdate but picking up only the first and the last record of every txt variable.

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Haikuo
Onyx | Level 15

I am not sure what you are really aiming for, but given the data as is, the following code can get what you want:

data have;

input txt &$11. DPFDATE  :date9.  SUBJID :$8.;

format dpfdate date9.;

cards;

SLOW INCRE   13DEC2006    10051001

ROUTINE DO   14DEC2006    10051001

ROUTINE DO   15DEC2006    10051001

ROUTINE DO   16DEC2006    10051001

ROUTINE DO   17DEC2006    10051001

ROUTINE DO   18DEC2006    10051001

ROUTINE DO   19DEC2006    10051001

ROUTINE DO   20DEC2006    10051001

ROUTINE DO   21DEC2006    10051001

ROUTINE DO  22DEC2006    10051001

ROUTINE DO  23DEC2006    10051001

ROUTINE DO  24DEC2006    10051001

ROUTINE DO  25DEC2006    10051001

ROUTINE DO  26DEC2006    10051001

ROUTINE DO  27DEC2006    10051001

ROUTINE DO  28DEC2006    10051001

ROUTINE DO  29DEC2006    10051001

ROUTINE DO  30DEC2006    10051001

ROUTINE DO  31DEC2006    10051001

;

data want;

set have;

by txt notsorted;

if (first.txt or last.txt);

run;

proc print;run;

Regards,

Haikuo

View solution in original post

2 REPLIES 2
Haikuo
Onyx | Level 15

I am not sure what you are really aiming for, but given the data as is, the following code can get what you want:

data have;

input txt &$11. DPFDATE  :date9.  SUBJID :$8.;

format dpfdate date9.;

cards;

SLOW INCRE   13DEC2006    10051001

ROUTINE DO   14DEC2006    10051001

ROUTINE DO   15DEC2006    10051001

ROUTINE DO   16DEC2006    10051001

ROUTINE DO   17DEC2006    10051001

ROUTINE DO   18DEC2006    10051001

ROUTINE DO   19DEC2006    10051001

ROUTINE DO   20DEC2006    10051001

ROUTINE DO   21DEC2006    10051001

ROUTINE DO  22DEC2006    10051001

ROUTINE DO  23DEC2006    10051001

ROUTINE DO  24DEC2006    10051001

ROUTINE DO  25DEC2006    10051001

ROUTINE DO  26DEC2006    10051001

ROUTINE DO  27DEC2006    10051001

ROUTINE DO  28DEC2006    10051001

ROUTINE DO  29DEC2006    10051001

ROUTINE DO  30DEC2006    10051001

ROUTINE DO  31DEC2006    10051001

;

data want;

set have;

by txt notsorted;

if (first.txt or last.txt);

run;

proc print;run;

Regards,

Haikuo

Linlin
Lapis Lazuli | Level 10

/* I add a observation to your original data: 

SLOW INCRE   23DEC2007    10051001 */

/* borrowed Haikuo's dataset */

data have;

input txt &$11. DPFDATE  :date9.  SUBJID :$8.;

format dpfdate date9.;

cards;

SLOW INCRE   13DEC2006    10051001

ROUTINE DO   14DEC2006    10051001

ROUTINE DO   15DEC2006    10051001

ROUTINE DO   16DEC2006    10051001

ROUTINE DO   17DEC2006    10051001

ROUTINE DO   18DEC2006    10051001

ROUTINE DO   19DEC2006    10051001

ROUTINE DO   20DEC2006    10051001

ROUTINE DO   21DEC2006    10051001

ROUTINE DO  22DEC2006    10051001

ROUTINE DO  23DEC2006    10051001

ROUTINE DO  24DEC2006    10051001

ROUTINE DO  25DEC2006    10051001

ROUTINE DO  26DEC2006    10051001

ROUTINE DO  27DEC2006    10051001

ROUTINE DO  28DEC2006    10051001

ROUTINE DO  29DEC2006    10051001

ROUTINE DO  30DEC2006    10051001

ROUTINE DO  31DEC2006    10051001

SLOW INCRE   23DEC2007    10051001

;

data temp;

set have;

n=_n_;

proc sort;

by txt n;

data want;

  set temp;

by txt;

if (first.txt or last.txt);

run;

proc print;run;

Obs       txt          DPFDATE     SUBJID      n

1     ROUTINE DO    14DEC2006    10051001     2

2     ROUTINE DO    31DEC2006    10051001    19

3     SLOW INCRE    13DEC2006    10051001     1

4     SLOW INCRE    23DEC2007    10051001    20

Linlin

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 2 replies
  • 676 views
  • 3 likes
  • 3 in conversation