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

Second_step is take data and  produce about 10 lines of output per 1 line read in. It does not.

Why is this code not producing results?

 

Data Second_step (keep =drawdate pbnum num1of2 num2of2);
 
 Set First_step(keep= Drawdate num1 num2 num3 num4 num5 pbnum multinum obs=2) ;
 array numsdrawn {6} num1 num2 num3 num4 num5 multinum;
 length num1of2 num2of2 8;
 
do I=1 to 4;
 num1of2 = numsdrawn(I) ;
 put @10 'NUM1of2 =' num1of2 2. @;
 do J = numsdrawn(I+1) to 5 ;
 num2of2 = numsdrawn(j);
 put @25 'num2of2=' @35 num2of2 2. @40 "J=" +2 J 2.;
 output;
 end;
 end;
 
 Run;
 
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

So you want to produce pairs of numbers from a list?  You second DO loops index variable is using the wrong starting value.

data second_step;
  set first_step;
  array numsdrawn num1-num5 ;
  do i=1 to dim(numsdrawn)-1;
    do j = i+1 to dim(numsdrawn) ;
      num1of2 = numsdrawn[i] ;
      num2of2 = numsdrawn[j];
      output;
    end;
  end;
  drop i j ;
run;

View solution in original post

3 REPLIES 3
Kurt_Bremser
Super User
data Second_step (keep=drawdate pbnum num1of2 num2of2);
set First_step (keep=Drawdate num1 num2 num3 num4 num5 pbnum multinum obs=2);
array numsdrawn {6} num1 num2 num3 num4 num5 multinum;
length num1of2 num2of2 8;
do I = 1 to 4;
  num1of2 = numsdrawn(I) ;
  put @10 'NUM1of2 =' num1of2 2. @; /* PUT writes to the log */
  do J = numsdrawn(I+1) to 5 ;
    num2of2 = numsdrawn(j);
    put @25 'num2of2=' @35 num2of2 2. @40 "J=" +2 J 2.; /* to the log */
    output; /* OUTPUT writes to the dataset named in the DATA statement */
  end;
end;
run;

A data step will not create output for the Output window/tab. Your data step PUTs some information to the log, and will write 40 observations (2 obs read, two DO loops 4 by 5 = 20) to the resulting dataset.

Either use an output producing procedure (e.g.PRINT), or redirect the output with a FILE PRINT statement.

Astounding
PROC Star

This statement is suspect:

do J = numsdrawn(I+1) to 5 ;

It tells SAS to use one of your variable values (num1 through num5) to indicate the starting point for the array.  More likely, you meant:

do J = I+1 to 5 ;
Tom
Super User Tom
Super User

So you want to produce pairs of numbers from a list?  You second DO loops index variable is using the wrong starting value.

data second_step;
  set first_step;
  array numsdrawn num1-num5 ;
  do i=1 to dim(numsdrawn)-1;
    do j = i+1 to dim(numsdrawn) ;
      num1of2 = numsdrawn[i] ;
      num2of2 = numsdrawn[j];
      output;
    end;
  end;
  drop i j ;
run;