I have the following SAS dataset, with a single columns called STAT
(This field contains a series of values for each record):
I need to create a new field called CountOpen
that, for each row, counts how many times the word Open
is contained in the field STAT
. So, from the example above, the resulting dataset would be:
Can someone help me, please?
I think that the count function does what you are looking for:
*Replicate data;
data dt;
infile cards dlm = ",";
length stat $30;
input stat;
cards;
Closed Open Open,
Closed Closed Open,
Open,
Open,
;
run;
*Compute countOpen using count;
data dt2;
set dt;
countOpen = count(stat, "Open");
run;
proc print data = dt2;
run;