0
votes

using loop function, I like to put variables in different columns in condition to the other variable in the data. I have trouble writing right loop statement because relocation variables keep going to the next row. Can someone point out what I did not get? I want my variables aligh like this : ft @10 m1 @30 m2 @31 m3 @32 m4 @34 o2 @35 o5 @36

data fttryone;

input ft m1 o2 m3 m4 o5;

datalines;

1 2 3 4 5 6

2 7 8 9 1 1

3 1 3 4 5 2

4 6 7 8 9 2

;

run;

data null;

set fttryone;

file 'C:\fttry18.txt';

put @10 ft

   @30 M1 

   @31 M3 

   @32 M4 

do i=0 to 4;

j=i*2;

if ft=i then

put @35+j o2

put @36+j o5;

run;

1
Can you clarify how this question is different from the one you asked yesterday? And please format your code. - itzy
I updated my answer on your other question "SAS: column position rearrangement"...have you tried using a trailing @ sign to prevent a new line? - Jay Corbett

1 Answers

3
votes

Three problems with your code:

  1. To keep your "relocation" variables (O2 and O3) on the same row in your output .txt file, you need to include two ampersand signs (@@) at the end of the line of code that puts variable M4.
  2. You have not closed out your DO loop with an END statement.
  3. You do not need the "PUT" in front of "@36+j o5;".

Try the following code:

data _null_;
    set fttryone;
    file 'C:\fttry18.txt';
    put   @10 ft
          @30 M1
          @31 M
          @32 M4 @@
     ;
     do i=0 to 4;
       if ft=i then do;
          j=i*2;
          put @35+j o2
              @36+j o5;
       end;
    end;
 run;