0

i have a result set like:

  Name number reg_type1 reg_type2 reg_type3 reg_type4 reg_type5 reg_type6 reg_type7
  aaa   123       Y         N       Y          N          Y       N         N
  bbb   234       N         N       Y          N          Y       N         N
  ccc   456       Y         N       Y          Y          N       Y         Y

and i want the result set like:

  Name   number      level1       level2        level3      level4      level5 
  aaa     123       reg_type1    reg_type3     reg_type5    NULL         NULL
  bbb     234       reg_type3    reg_type5        NULL      NULL         NULL
  ccc     456       reg_type1    reg_type3     reg_type4    reg_type6   reg_type7

Thanks!!

2
  • The title and the question don't match, in addition to the answer you posted not matching either one. What are you doing here? Commented Jul 25, 2013 at 2:50
  • Making things a SNAFU, apparently. My apologies. Commented Jul 25, 2013 at 17:02

1 Answer 1

1

To answer what's in the question (as opposed to the title), this is easily done with array:

data have;
input Name $  number (reg_type1-reg_type7) ($);
datalines;
aaa   123       Y         N       Y          N          Y       N         N
bbb   234       N         N       Y          N          Y       N         N
ccc   456       Y         N       Y          Y          N       Y         Y
;;;;
run;
data want;
set have;
array regs reg:;
length level1-level5 $15;
array level[5] $;
_l = 1;
do _t = 1 to dim(regs);
 if regs[_t]='Y' then do;
   level[_l]=vname(regs[_t]);
   _l = _l+1;
 end;
end;
run;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.