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;
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;
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
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;
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;
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.
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.