Hi All, Please help, i am stuck with my code. Source table: Id Gender Marks 1 F Eng lish 1 F 2 M Maths 2 M English 2 M Science 2 M 3 F Maths 4 M Eng lish 4 M Maths 4 M 4 M Social Required output: Id Gender Eng_lish Maths Science Social 1 Y 2 Y Y Y 3 Y 4 Y Y Y I am using transpose and sas macros to get the above output. ID NAME OF FORMER COL1 COL2 COL3 COL4 COL5 VARIABLE 1 Marks_new Eng lish 2 Marks_new Maths Eng lish Science 3 Marks_new Maths 4 Marks_new Maths Eng lish Maths Social After transposing, counting COL1 - COL..n to do the loop. I am using COL count and variable count to do the loop. Since variable names are having space i am using tranwrd to replace space with '_' and assigning original value as Label. My SAS code: Data t; input ID Gender $ Marks $50.; cards; 1 F Eng lish 1 F 2 M Maths 2 M Eng lish 2 M Science 2 M 3 F Maths 4 M Maths 4 M Eng lish 4 M Maths 4 M 4 M Social ; data tt; set t; Marks_new=compress(Marks, ""); run; PROC TRANSPOSE DATA=tt OUT=t1; BY id; VAR Marks_new; RUN; proc contents data=t1 out=list (keep=Name); run; proc sql; select count(compress(name,,'kd')) into: ct from list where name ne""; select count(distinct Marks) into: var_ct from tt where Marks ne ""; select distinct Marks_new into: var1-: var%eval(&var_ct) from tt where Marks ne ""; select distinct Marks into: label1-: label%eval(&var_ct) from tt where Marks ne ""; quit; %put &lqbel1 &var1; %macro m(); %if &ct. > &var_ct. %then %do; data my (drop = Col1-&Col%eval(&ct); set t1; %DO i=1 %TO &ct.; %IF COL&i= &&var&i.. %THEN %cmpres(&&var&i..)='Y'; &&var&i.. label = &&label&i..; %end; run; %end; %else &ct. < &var_ct. %then %do; data my (drop = Col1-&Col%eval(&var_ct); set t1; %DO i=1 %TO &var_ct.; %IF COL&i= &&var&i.. %THEN %cmpres(&&var&i..)='Y'; &&var&i.. label = &&label&i..; %end; run; %end; %mend; %m(); Many thanks in advance. Regards, Raj
... View more