I want to take a dataset that has things grouped by a number, and then a subgroup. For instance, Group 1 has subgroups 1a, 1b, 1c, 1d, etc. (the number of subgroups is dynamic) and each subgroup could be at one of three different levels (1,2,3). The data I have now, each subgroup would be it's own observation. What I want is to compress it down so that I have a single group at each level - and for all of the subgroups that are at the same level to be in that observation. Again, I don't know how to phrase the question that I want to ask, so I've tried to provide examples. How do I take the data in the "have" dataset from below and turn it into the "want" dataset? Thank you for your time. data have; length unitid $6 group $5 subgroup $7 level $1; infile datalines dlm=',' dsd; input unitid $ group $ subgroup $ level $; return; datalines; "000001","05.02","05.0201","1" "000001","05.02","05.0202","1" "000001","05.02","05.0203","1" "000001","05.02","05.0207","1" "000001","05.02","05.0299","2" "000001","05.02","05.0299","3" "000002","05.02","05.0201","1" "000002","05.02","05.0203","1" "000002","05.02","05.0207","1" "000002","05.02","05.0202","2" "000002","05.02","05.0203","2" "000002","05.02","05.0207","2" "000002","05.02","05.0202","3" ; run; data want; length id $6 group $6 level $1 subgroup1 $1 subgroup2 $1 subgroup3 $1 subgroup4 $1 subgroup5 $1; infile datalines dlm=',' dsd; input id $ group $ level $ subgroup1 $ subgroup2 $ subgroup3 $ subgroup4 $ subgroup5 $; return; datalines; "000001","group1","1","a","b","c","d", "000001","group1","2",,,,,"e" "000001","group1","3",,,,,"e" "000002","group1","1","a",,"c","d", "000002","group1","2",,"b","c","d", "000002","group1","3",,"b",,, ; run;
... View more