## How to I delete all the columns that are zero in the following matrix

Solved
Super Contributor
Posts: 328

# How to I delete all the columns that are zero in the following matrix

SurvivalM=J(nrow(survival1),1,1);

do i = 1 to n;

if censored=1 then SurvivalM=survival1; else if censored[1]=0 then SurvivalM=survival1/*****Create a 1 by N -matrix of Survival ****/;

end;

print SurvivalM;

InverseC=J(nrow(survival1),1,1);

do i = 1 to n;

if censored=1 then InverseC=1/survival1; else if censored[1]=0 then InverseC=0/*****survivalC is the imputed censored survival and set the real Survivalval to 1**/;

end;

print InverseC;

m=frequency[1];

*Big=J(nrow(DM),m,value);

test = j(nrow(InverseC),1,1);

Big=SurvivalM*t( InverseC[loc(test^=0)]);

print Big;

 ROW1 ROW2 ROW3 ROW4 ROW5 ROW6 ROW7 ROW8 ROW9 ROW10 ROW11 ROW12 ROW13 ROW14 ROW15 ROW16 ROW17 ROW18 ROW19 ROW20 0 0 1.08754 0 0 0 0 0 0 0 0 0 0 0 0 4.10159 0 0 0 0 0 0 1.0303 0 0 0 0 0 0 0 0 0 0 0 0 3.88571 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 3.77143 0 0 0 0 0 0 0.969697 0 0 0 0 0 0 0 0 0 0 0 0 3.65714 0 0 0 0 0 0 0.909091 0 0 0 0 0 0 0 0 0 0 0 0 3.42857 0 0 0 0 0 0 0.848485 0 0 0 0 0 0 0 0 0 0 0 0 3.2 0 0 0 0 0 0 0.787879 0 0 0 0 0 0 0 0 0 0 0 0 2.97143 0 0 0 0 0 0 0.727273 0 0 0 0 0 0 0 0 0 0 0 0 2.74286 0 0 0 0 0 0 0.666667 0 0 0 0 0 0 0 0 0 0 0 0 2.51429 0 0 0 0 0 0 0.606061 0 0 0 0 0 0 0 0 0 0 0 0 2.28571 0 0 0 0 0 0 0.545454 0 0 0 0 0 0 0 0 0 0 0 0 2.05714 0 0 0 0 0 0 0.484849 0 0 0 0 0 0 0 0 0 0 0 0 1.82857 0 0 0 0 0 0 0.424242 0 0 0 0 0 0 0 0 0 0 0 0 1.6 0 0 0 0 0 0 0.363636 0 0 0 0 0 0 0 0 0 0 0 0 1.37143 0 0 0 0 0 0 0.30303 0 0 0 0 0 0 0 0 0 0 0 0 1.14286 0 0 0 0 0 0 0.265151 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0.227273 0 0 0 0 0 0 0 0 0 0 0 0 0.857143 0 0 0 0 0 0 0.151515 0 0 0 0 0 0 0 0 0 0 0 0 0.571429 0 0 0 0 0 0 0.0757576 0 0 0 0 0 0 0 0 0 0 0 0 0.285714 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Accepted Solutions
Solution
‎02-01-2013 07:53 PM
Super Contributor
Posts: 1,636

## Re: How to I delete all the columns that are zero in the following matrix

Posted in reply to desireatem

sample code:

data have;

input row \$ v1-v5;

cards;

r1 2 0 0 0 3

r2 5 3 0 0 8

;

proc sql noprint;

select catx(' ','sum(',name,') as',name) into : list separated by ','

from dictionary.columns

where libname='WORK' and memname='HAVE' and type='num';

create table temp as

select &list from have;

quit;

data _null_;

set temp;

length _list \$ 4000;

array _x{*} _numeric_;

do i=1 to dim(_x);

if _x{i} eq 0 then _list=catx(' ',_list,vname(_x{i}));

end;

call symputx('drop',_list);

run;

data want;

set have(drop=&drop);

run;

proc print;run;

Obs    row    v1    v2    v5

1     r1      2     0     3

2     r2      5     3     8

All Replies
Solution
‎02-01-2013 07:53 PM
Super Contributor
Posts: 1,636

## Re: How to I delete all the columns that are zero in the following matrix

Posted in reply to desireatem

sample code:

data have;

input row \$ v1-v5;

cards;

r1 2 0 0 0 3

r2 5 3 0 0 8

;

proc sql noprint;

select catx(' ','sum(',name,') as',name) into : list separated by ','

from dictionary.columns

where libname='WORK' and memname='HAVE' and type='num';

create table temp as

select &list from have;

quit;

data _null_;

set temp;

length _list \$ 4000;

array _x{*} _numeric_;

do i=1 to dim(_x);

if _x{i} eq 0 then _list=catx(' ',_list,vname(_x{i}));

end;

call symputx('drop',_list);

run;

data want;

set have(drop=&drop);

run;

proc print;run;

Obs    row    v1    v2    v5

1     r1      2     0     3

2     r2      5     3     8

Super Contributor
Posts: 328

## Re: How to I delete all the columns that are zero in the following matrix

Thanks, what do I do if I want the the columns to be V1, V2, V3 , without skippying numbers

Super Contributor
Posts: 1,636

## Re: How to I delete all the columns that are zero in the following matrix

Posted in reply to desireatem

Sorry, I don't understand your question. v3,v4 were deleted in my example because they have all zeros.

Super Contributor
Posts: 328

## Re: How to I delete all the columns that are zero in the following matrix

Thanks, do you know how to delete rows within proc iml. I created this matrix in proc iml and want to delete the rows of 1s

Super Contributor
Posts: 1,636

## Re: How to I delete all the columns that are zero in the following matrix

Posted in reply to desireatem

Sorry, I don't use proc iml.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
• 5 replies
• 643 views
• 0 likes
• 2 in conversation