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

My dear friends,

How can I mark an intervall? I like to to mark the first Top_layer and the first Bottom_layer to be marked. I like to show the inside of a layer by marking it to number one. Please look at my dataset:

 

Please notice that the LAYER_NAME is changing (from A to C)

 

A Top_layer never starts at one LAYER_NAME and ends in another LAYER_NAME. All top layers and bottom layers belong to a specific layer_name

 

LAYER_NAMEDEPTHTop_layerBottom_layerMARK
A0.. 
A0,5.. 
A1.. 
A1,51,5.1
A2..1
A2,5..1
A3..1
A3,5..1
A4..1
A4,5..1
A5..1
A5,5.5,51
A6.. 
A6,5.. 
A7.. 
A7,57,5.1
A8..1
A8,5..1
A9.91
A9,5.. 
A10.. 
B0.. 
B0,50,5.1
B1..1
B1,5..1
B2.2,51
B2,5.. 
B3.. 
B3,5.. 
B4.. 
B4,5.. 
C0.. 
C0,5.. 
C11.1
C1,5..1
C2..1
C2,5..1
C3.31
C3,5.. 
C4.. 
C4,5.. 
C55.1
C5,5..1
C6.61
C6,5...
C7...
C7,57,5.1
C8..1
C8,5.8,51
C9.. 
C9,5.. 
C10.. 

 

I would be very grateful if you help me with this 

 

Thank you very much in advance

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Here is one way

 

data have;
input LAYER_NAME $1 MD_FT 3-5 Top_layer 7-9 Bottom_layer 11-13;
infile datalines dlm='|';
datalines;
A|0  |.  |.
A|0.5|.  |.
A|1  |.  |.
A|1.5|1.5|.  
A|2  |.  |.  
A|2.5|.  |.  
A|3  |.  |.  
A|3.5|.  |.  
A|4  |.  |.  
A|4.5|.  |.  
A|5  |.  |.  
A|5.5|.  |5.5
A|6  |.  |.
A|6.5|.  |.
A|7  |.  |.
A|7.5|7.5|.  
A|8  |.  |.  
A|8.5|.  |.  
A|9  |.  |9  
A|9.5|.  |.
A|10 |.  |.
B|0  |.  |.
B|0.5|0.5|.  
B|1  |.  |.  
B|1.5|.  |.  
B|2  |.  |2.5
B|2.5|.  |.
B|3  |.  |.
B|3.5|.  |.
B|4  |.  |.
B|4.5|.  |.
C|0  |.  |.
C|0.5|.  |.
C|1  |1  |.  
C|1.5|.  |.  
C|2  |.  |.  
C|2.5|.  |.  
C|3  |.  |3  
C|3.5|.  |.
C|4  |.  |.
C|4.5|.  |.
C|5  |5  |.  
C|5.5|.  |.  
C|6  |.  |6  
C|6.5|.  |.  
C|7  |.  |.  
C|7.5|7.5|.  
C|8  |.  |.  
C|8.5|.  |8.5
C|9  |.  |.
C|9.5|.  |.
C|10 |.  |.
;

data want;
    set have;
    if Top_layer ne . then mark=1;
    if Bottom_layer ne . then do;
        output;
        mark=.;
        return;
    end;
    output;
    retain mark;
run;

 

 

Result:

 

 

LAYER_NAME  DEPTH   Top_layer Bottom_layer  MARK
A           0       .         .             .
A           0.5     .         .             .
A           1       .         .             .
A           1.5     1.5       .             1
A           2       .         .             1
A           2.5     .         .             1
A           3       .         .             1
A           3.5     .         .             1
A           4       .         .             1
A           4.5     .         .             1
A           5       .         .             1
A           5.5     .         5.5           1
A           6       .         .             .
A           6.5     .         .             .
A           7       .         .             .
A           7.5     7.5       .             1
A           8       .         .             1
A           8.5     .         .             1
A           9       .         9             1
A           9.5     .         .             .
A           10      .         .             .
B           0       .         .             .
B           0.5     0.5       .             1
B           1       .         .             1
B           1.5     .         .             1
B           2       .         2.5           1
B           2.5     .         .             .
B           3       .         .             .
B           3.5     .         .             .
B           4       .         .             .
B           4.5     .         .             .
C           0       .         .             .
C           0.5     .         .             .
C           1       1         .             1
C           1.5     .         .             1
C           2       .         .             1
C           2.5     .         .             1
C           3       .         3             1
C           3.5     .         .             .
C           4       .         .             .
C           4.5     .         .             .
C           5       5         .             1
C           5.5     .         .             1
C           6       .         6             1
C           6.5     .         .             .
C           7       .         .             .
C           7.5     7.5       .             1
C           8       .         .             1
C           8.5     .         8.5           1
C           9       .         .             .
C           9.5     .         .             .
C           10      .         .             .

 

View solution in original post

5 REPLIES 5
PeterClemmensen
Tourmaline | Level 20

Here is one way

 

data have;
input LAYER_NAME $1 MD_FT 3-5 Top_layer 7-9 Bottom_layer 11-13;
infile datalines dlm='|';
datalines;
A|0  |.  |.
A|0.5|.  |.
A|1  |.  |.
A|1.5|1.5|.  
A|2  |.  |.  
A|2.5|.  |.  
A|3  |.  |.  
A|3.5|.  |.  
A|4  |.  |.  
A|4.5|.  |.  
A|5  |.  |.  
A|5.5|.  |5.5
A|6  |.  |.
A|6.5|.  |.
A|7  |.  |.
A|7.5|7.5|.  
A|8  |.  |.  
A|8.5|.  |.  
A|9  |.  |9  
A|9.5|.  |.
A|10 |.  |.
B|0  |.  |.
B|0.5|0.5|.  
B|1  |.  |.  
B|1.5|.  |.  
B|2  |.  |2.5
B|2.5|.  |.
B|3  |.  |.
B|3.5|.  |.
B|4  |.  |.
B|4.5|.  |.
C|0  |.  |.
C|0.5|.  |.
C|1  |1  |.  
C|1.5|.  |.  
C|2  |.  |.  
C|2.5|.  |.  
C|3  |.  |3  
C|3.5|.  |.
C|4  |.  |.
C|4.5|.  |.
C|5  |5  |.  
C|5.5|.  |.  
C|6  |.  |6  
C|6.5|.  |.  
C|7  |.  |.  
C|7.5|7.5|.  
C|8  |.  |.  
C|8.5|.  |8.5
C|9  |.  |.
C|9.5|.  |.
C|10 |.  |.
;

data want;
    set have;
    if Top_layer ne . then mark=1;
    if Bottom_layer ne . then do;
        output;
        mark=.;
        return;
    end;
    output;
    retain mark;
run;

 

 

Result:

 

 

LAYER_NAME  DEPTH   Top_layer Bottom_layer  MARK
A           0       .         .             .
A           0.5     .         .             .
A           1       .         .             .
A           1.5     1.5       .             1
A           2       .         .             1
A           2.5     .         .             1
A           3       .         .             1
A           3.5     .         .             1
A           4       .         .             1
A           4.5     .         .             1
A           5       .         .             1
A           5.5     .         5.5           1
A           6       .         .             .
A           6.5     .         .             .
A           7       .         .             .
A           7.5     7.5       .             1
A           8       .         .             1
A           8.5     .         .             1
A           9       .         9             1
A           9.5     .         .             .
A           10      .         .             .
B           0       .         .             .
B           0.5     0.5       .             1
B           1       .         .             1
B           1.5     .         .             1
B           2       .         2.5           1
B           2.5     .         .             .
B           3       .         .             .
B           3.5     .         .             .
B           4       .         .             .
B           4.5     .         .             .
C           0       .         .             .
C           0.5     .         .             .
C           1       1         .             1
C           1.5     .         .             1
C           2       .         .             1
C           2.5     .         .             1
C           3       .         3             1
C           3.5     .         .             .
C           4       .         .             .
C           4.5     .         .             .
C           5       5         .             1
C           5.5     .         .             1
C           6       .         6             1
C           6.5     .         .             .
C           7       .         .             .
C           7.5     7.5       .             1
C           8       .         .             1
C           8.5     .         8.5           1
C           9       .         .             .
C           9.5     .         .             .
C           10      .         .             .

 

farshidowrang
Quartz | Level 8

I'm very grateful

Thank you!

Ksharp
Super User
data want;
 set have;
retain mark;
if lag(Bottom_layer) then mark=.;
if Top_layer then mark=1;
run;
farshidowrang
Quartz | Level 8

Thank you very much

 

I'm very grateful

hashman
Ammonite | Level 13

@farshidowrang:

Methinks the simplest could be:

data want ;                                                                                                                             
  set have ;                                                                                                                            
  retain mark ;                                                                                                                         
  if top_layer then mark = 1 ;                                                                                                          
  output ;                                                                                                                              
  if bottom_layer then mark = . ;                                                                                                       
run ;        

Kind regards

Paul D. 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 460 views
  • 0 likes
  • 4 in conversation