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