Hi,
I want all the 'N' varibales and their id's
data have;
input ID AAA$ BBB$ CCC$ DDD$ ;
cards;
11 Y N Y N
12 Y Y N Y
13 N N N Y
14 N N N N
run;
want:
11 BBB
12 CCC
13 AAA BBB CCC
14 AAA BBB CCC DDD
Please also try alternativey
data want;
set have;
array new(4) AAA BBB CCC DDD;
do i = 1 to 4;
if new(i)='N' then new2=vname(new(i));
if new2 ne '' then output;
end;
run;
proc sort data=want nodupkey;
by id new2;
run;
proc transpose data=want out=trans(drop=_name_);
by id;
var new2;
run;
Thanks,
Jag
This might get you what you want. I put the dummy (id = 10) in their to keep the columns in order for the final output. Not exactly the presentation you have but it's close.
data have;
input ID AAA$ BBB$ CCC$ DDD$ ;
cards;
10 N N N N
11 Y N Y N
12 Y Y N Y
13 N N N Y
14 N N N N
;
run;
proc transpose data=have out=prep(where=(col1 = 'N'));by id;var aaa bbb ccc ddd;
proc transpose data=prep out=prep2(drop=_label_ _name_);by id;var _NAME_;
data want;
set prep2;
if id = 10 then delete;
run;
data want;
set have;
array vars aaa--ddd;
length temp $20.;
do i=1 to dim(vars);
if vars(i)='N' then do;
temp=catx(' ',temp,vname(vars(i)));
n=count(catx(' ',of vars(*)),'N');
end;
end;
call missing(of vars(*));
do j=1 to n;
vars(j)=scan(temp,j);
end;
keep id aaa--ddd;
run;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.