DATA Step, Macro, Functions and more

unsecheduled visit number same day have two dates

Reply
Occasional Contributor
Posts: 15

unsecheduled visit number same day have two dates

Hi 

I want  visitno 1.1  101,unsecheduled-20/mar/2018 in this  first five observations  and next five observation's is  visitno 1.2 how to do
data exp;
length uv $200;
infile datalines dsd truncover;
input id uv $ visitno;
datalines;
101,,1
101,unsecheduled-20/mar/2018
101,unsecheduled-20/mar/2018
101,unsecheduled-20/mar/2018
101,unsecheduled-20/mar/2018
101,unsecheduled-20/mar/2018
101,unsecheduled-21/mar/2018
101,unsecheduled-21/mar/2018
101,unsecheduled-21/mar/2018
101,unsecheduled-21/mar/2018
101,unsecheduled-21/mar/2018
101,,2
;
run;

 

Super User
Super User
Posts: 9,416

Re: unsecheduled visit number same day have two dates

Good idea to show what the output should look like.  This is first draft to show groupings, you would need to fiddle with the if's to get exactly what you want;

data want;
  set exp (rename=(visitno=v));
  retain visitno tmp;
  by id uv notsorted;
  if first.id then tmp=0;
  if first.uv and uv="" then do;
    tmp=tmp+0.1;
    visitno=v+tmp;
  end;
run;
Occasional Contributor
Posts: 15

Re: unsecheduled visit number same day have two dates

your placed all visitno 1.1 but i want this way here unsecheduled different date's .so i want this structure 

uv                                                           visitno 

unsecheduled-20/mar/2018                    1.1

unsecheduled-20/mar/2018                    1.1

unsecheduled-20/mar/2018                    1.1

unsecheduled-20/mar/2018                    1.1

unsecheduled-20/mar/2018                    1.1

unsecheduled-21/mar/2018                    1.2

unsecheduled-21/mar/2018                    1.2

unsecheduled-21/mar/2018                    1.2

unsecheduled-21/mar/2018                    1.2

unsecheduled-21/mar/2018                    1.2

Occasional Contributor
Posts: 15

Re: unsecheduled visit number same day have two dates

i dont want all visit no 1.1 first 5 placed 1.1 next 5 placed 1.2 because uu first 5 subjects different date next 5 different .
Super User
Super User
Posts: 9,416

Re: unsecheduled visit number same day have two dates

As I said, fiddle with the if's to get what you want, as you haven't posted example output.  I would guess:

data want;
  set exp (rename=(visitno=v));
  retain visitno tmp;
  by id uv notsorted;
  if first.id then tmp=0;
  if first.uv and uv="" then do;
    tmp=tmp+0.1;
    visitno=v+tmp;
  end;
  if first.uv and un ne "" then do;
    tmp=tmp+0.1;
    visitno=v+tmp;
  end;
run;
PROC Star
Posts: 1,582

Re: unsecheduled visit number same day have two dates

Assuming i understand what you want:

 

data exp;
length uv $200;
infile datalines dsd truncover;
input id uv $ visitno;
datalines;
101,,1
101,unsecheduled-20/mar/2018
101,unsecheduled-20/mar/2018
101,unsecheduled-20/mar/2018
101,unsecheduled-20/mar/2018
101,unsecheduled-20/mar/2018
101,unsecheduled-21/mar/2018
101,unsecheduled-21/mar/2018
101,unsecheduled-21/mar/2018
101,unsecheduled-21/mar/2018
101,unsecheduled-21/mar/2018
101,,2
;
run;

data want;
set exp;
by id;
retain _v;
_k=lag(uv);
if first.id then call missing(_v);
if visitno then _v=visitno;
else if missing(lag(uv)) then _v+.1;
else if _k ne uv then  _v+.1;
if missing(visitno) then visitno=_v;
drop _:;
run;
Ask a Question
Discussion stats
  • 5 replies
  • 157 views
  • 0 likes
  • 3 in conversation