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

This is the code that I am using;

    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**/;

   

     *InverseCC=J(nrow(survival1),1,1);

end;

      print InverseC;

Big=SurvivalM*t(InverseC);

print BIG;

/*** for this code I want to delete all colums of BIG where row1 and col1 are zero ***/;

BIGG=J(nrow(BIGG),20,1);

do 1 to n;

if col[i,1]=0 then delete;

end;

print BIGG;

statement : ASSIGN at line 4338 column 1

4339  do 1 to n;

         -

         22

         200

ERROR 22-322: Syntax error, expecting one of the following: a name, ;, DATA, UNTIL, WHILE.

ERROR 200-322: The symbol is not recognized and will be ignored.

4340  if col[i,1]=0 then delete;

4341  end;

ERROR: END does not occur within DO group at line=4341 col=1.

4342  print BIGG;

ERROR: Matrix BIGG has not been set to a value.

statement : PRINT at line 4342 column 1

1 ACCEPTED SOLUTION

Accepted Solutions
IanWakeling
Barite | Level 11

Use something like:

reduced=BIG[, loc( BIG[ 1,]^= 0 )];

so use the result of the loc function to pick out the list of columns required.  The same technique can be used to remove zeros from the vector in one of your other questions.

Ian.

View solution in original post

4 REPLIES 4
desireatem
Pyrite | Level 9

I created this matrix 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

and want to create another matrix BIGG by deleting all the colums that have first element equal zero in BIG to produce the matrix BIGG.

This is the wrong code;

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**/;

   

     *InverseCC=J(nrow(survival1),1,1);

end;

      print InverseC;

Big=SurvivalM*t(InverseC);

print BIG;

/*** for this code I want to delete all colums of BIG where row1 and col1 are zero ***/;

BIGG=J(nrow(BIGG),20,1);

do 1 to n;

if col[i,1]=0 then delete;

end;

print BIGG;

statement : ASSIGN at line 4338 column 1

4339  do 1 to n;

         -

         22

         200

ERROR 22-322: Syntax error, expecting one of the following: a name, ;, DATA, UNTIL, WHILE.

ERROR 200-322: The symbol is not recognized and will be ignored.

4340  if col[i,1]=0 then delete;

4341  end;

ERROR: END does not occur within DO group at line=4341 col=1.

4342  print BIGG;

ERROR: Matrix BIGG has not been set to a value.

statement : PRINT at line 4342 column 1

IanWakeling
Barite | Level 11

Use something like:

reduced=BIG[, loc( BIG[ 1,]^= 0 )];

so use the result of the loc function to pick out the list of columns required.  The same technique can be used to remove zeros from the vector in one of your other questions.

Ian.

Rick_SAS
SAS Super FREQ

Here is my advice: Your questions are all the same because you are working on a big problem. Do something easy like

u = 1:5;

v = {0,1,0,0,1};

Figure out how to do what you want with small vectors and matrices. After you understand the small simple case, the bigproblem will fall.

It will also make it easier for people on the discussion forum to answer your questions.  A lot of people just hit the DELETE button if there isn't a short, simple, cut-an-paste example that illustrates the question.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 4 replies
  • 1193 views
  • 5 likes
  • 3 in conversation