BookmarkSubscribeRSS Feed
teja5959
Fluorite | Level 6

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
Fluorite | Level 6

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
Fluorite | Level 6
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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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