DATA ALL ;
SET ALL ;
by pa_id sa_id admin notsorted;
IF first.admin then seq +1;
run;Dear all,
I need your unreserved help. I am using SAS version 9.4. I want to count admin variable in cumulative fashion for value "o" by pa_id, sa_id, time.
the structure of the data is given below
I am expecting like this
data have;
input pa_id sa_id time Admin $;
cards;
1 11 23 o
1 11 36 o
1 11 82 p
1 12 45 o
1 12 55 p
1 12 67 o
1 12 70 o
1 12 90 o
2 13 36 o
2 13 46 o
2 13 59 p
2 14 25 p
2 14 34 o
2 14 40 p
;
data want;
set have;
by pa_id sa_id;
if first.sa_id then do; count=0;cum_count=1;end;
else cum_count+1;
if admin='o' then count+1;
run;
I'm afraid pics or screen shots doesn't help in ease of copy pasting the data values
untested
data want;
set have;
by pa_id sa_id;
if first.sa_id then do; count=0;cum_count=1;end;
else cum_count+1;
if admin='o' then count+1;
run;
data have;
input pa_id sa_id time Admin $;
cards;
1 11 23 o
1 11 36 o
1 11 82 p
1 12 45 o
1 12 55 p
1 12 67 o
1 12 70 o
1 12 90 o
2 13 36 o
2 13 46 o
2 13 59 p
2 14 25 p
2 14 34 o
2 14 40 p
;
data want;
set have;
by pa_id sa_id;
if first.sa_id then do; count=0;cum_count=1;end;
else cum_count+1;
if admin='o' then count+1;
run;
Thank you in advance.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.