BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
desireatem
Pyrite | Level 9

   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
1 ACCEPTED SOLUTION

Accepted Solutions
Linlin
Lapis Lazuli | Level 10

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

5 REPLIES 5
Linlin
Lapis Lazuli | Level 10

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

desireatem
Pyrite | Level 9

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

Linlin
Lapis Lazuli | Level 10

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

desireatem
Pyrite | Level 9

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

Linlin
Lapis Lazuli | Level 10

Sorry, I don't use proc iml.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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