Hello everyone, I have a dataset in the following form: data have;
infile datalines delimiter=",";
input ID $ x1 x2 x3;
datalines;
id1, 1, 2, 2
id1, 1, 2, 1
id2, 2, 2, 2
id3, 1, 2, 1
; I would like to count the number of times 1 appears in a row for each of the ID variables. In this case the result would look like: id1, 3
id2, 0
id3, 2 My actual data set has a few hundred IDs and about 20 variables of interest (unfortunately with no patterned naming scheme like I have here). Is there a slick way to accomplish this? I'd prefer not to make a long list of variables with something like: if x1 = 1 then x1_ind = 1 else x1_ind = 0; but if that's what needs to be done then so be it. Thanks!
... View more