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

Accepted Solution Solved
Reply
Super Contributor
Posts: 297
Accepted Solution

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;

ROW1001.08754210000000000004.10158730000
ROW2001.0303030000000000003.88571430000
ROW30010000000000003.77142860000
ROW4000.9696970000000000003.65714290000
ROW5000.90909090000000000003.42857140000
ROW6000.84848480000000000003.20000
ROW7000.78787880000000000002.97142860000
ROW8000.72727270000000000002.74285710000
ROW9000.66666670000000000002.51428570000
ROW10000.60606060000000000002.28571430000
ROW11000.54545450000000000002.05714290000
ROW12000.48484850000000000001.82857140000
ROW13000.42424240000000000001.60000
ROW14000.36363640000000000001.37142860000
ROW15000.30303030000000000001.14285710000
ROW16000.265151500000000000010000
ROW17000.22727270000000000000.85714290000
ROW18000.15151520000000000000.57142860000
ROW19000.07575760000000000000.28571430000
ROW2000000000000000000000

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

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

View solution in original post


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

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: 297

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

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

Super Contributor
Posts: 297

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

Sorry, I don't use proc iml.

☑ This topic is SOLVED.

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

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