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

I have the following data set.  I would like to create another separate array c1_1-c1_10 and c2_1-c2_1 where they are assigned 1 from the start a{1, j} >0 till b{i, j}=1.  For example, a1_3 through a1_7 is equal to 1.  And, b1_5 is equal to 1.  Therefore, the array c1_1 - c1_10 would have c1_3 through c1_5 equal to 1 and rest equal to ".".   Let me know if you need further clarification.  Thank you.

 

data a;
input a1_1-a1_10 a2_1-a2_10 b1_1-b1_10 b2_1-b2_10;
datalines;
. . 1 1 1 1 1 . . . . . . . 1 1 1 1 1 . . . . . . 1 . . . . . . . . 1 . . . . .
run;

 

Would like to the result to look something like following data set.


data c;
input c1_1-c1_10 c2_1-c2_10;
datalines;
. . 1 1 1 1 . . . . . . . . 1 . . . . .
run;

 

c1_1  c1_2  c1_3 c1_4 c1_5 c1_6 c1_7 c1_8 c1_9 c1_10   c2_1 c2_2 c2_3 c2_4 c2_5 c2_6 c2_7 c2_8 c2_9 c2_10

.            .       1       1       1      1         .       .           .    .             .       .        .         .        1      .          .      .       .           .  

 

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

Like this?

data HAVE;
  input A1_1-A1_10 A2_1-A2_10 B1_1-B1_10 B2_1-B2_10;
datalines;
. . 1 1 1 1 1 . . . . . . . 1 1 1 1 1 . . . . . . 1 . . . . . . . . 1 . . . . .
run;

data WANT; 
  array A1_[10]; 
  array A2_[10]; 
  array B1_[10]; 
  array B2_[10]; 
  array C1_[10]; 
  array C2_[10]; 
  set HAVE;
  do I=whichn(1,of A1_[*]) to whichn(1,of B1_[*]);
    C1_[I]=1;
  end;
  do I=whichn(1,of A2_[*]) to whichn(1,of B2_[*]);
    C2_[I]=1;
  end;
run;

proc print noobs;
  var C:;
run;
  
C1_1 C1_2 C1_3 C1_4 C1_5 C1_6 C1_7 C1_8 C1_9 C1_10 C2_1 C2_2 C2_3 C2_4 C2_5 C2_6 C2_7 C2_8 C2_9 C2_10
. . 1 1 1 1 . . . . . . . . 1 . . . . .

 

 

View solution in original post

2 REPLIES 2
ballardw
Super User

@smend wrote:

I have the following data set.  I would like to create another separate array c1_1-c1_10 and c2_1-c2_1 where they are assigned 1 from the start a{1, j} >0 till b{i, j}=1. 

 

For example, a1_3 through a1_7 is equal to 1. 

And, b1_5 is equal to 1. 

Therefore, the array c1_1 - c1_10 would have c1_3 through c1_5 equal to 1 and rest equal to ".". 

I am not seeing the impact role of the B variable, and what happens with there are gaps in a1_3 through a1_7 (such as a1_5 is missing)

 

Hint: cut back on the scale so you can provide more concrete examples, such as a1_1 to a1_5  instead of a1_10 and provide a few more worked examples.

Your statement:

Therefore, the array c1_1 - c1_10 would have c1_3 through c1_5 equal to 1 and rest equal to ".". 

looks a lot like c1_1-c1_10 is a copy of a1_1 to a1_10. If not provide why not.

 

Since you haven't shown any definitions for arrays that might help as to what you think an array in this instance would be. I see potential for at least 6 arrays in the solution.

 

ChrisNZ
Tourmaline | Level 20

Like this?

data HAVE;
  input A1_1-A1_10 A2_1-A2_10 B1_1-B1_10 B2_1-B2_10;
datalines;
. . 1 1 1 1 1 . . . . . . . 1 1 1 1 1 . . . . . . 1 . . . . . . . . 1 . . . . .
run;

data WANT; 
  array A1_[10]; 
  array A2_[10]; 
  array B1_[10]; 
  array B2_[10]; 
  array C1_[10]; 
  array C2_[10]; 
  set HAVE;
  do I=whichn(1,of A1_[*]) to whichn(1,of B1_[*]);
    C1_[I]=1;
  end;
  do I=whichn(1,of A2_[*]) to whichn(1,of B2_[*]);
    C2_[I]=1;
  end;
run;

proc print noobs;
  var C:;
run;
  
C1_1 C1_2 C1_3 C1_4 C1_5 C1_6 C1_7 C1_8 C1_9 C1_10 C2_1 C2_2 C2_3 C2_4 C2_5 C2_6 C2_7 C2_8 C2_9 C2_10
. . 1 1 1 1 . . . . . . . . 1 . . . . .

 

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 972 views
  • 0 likes
  • 3 in conversation