BookmarkSubscribeRSS Feed
teja5959
Obsidian | Level 7

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;

 

5 REPLIES 5
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;
teja5959
Obsidian | Level 7

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

teja5959
Obsidian | Level 7
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 .
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;
novinosrin
Tourmaline | Level 20

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;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1685 views
  • 0 likes
  • 3 in conversation