Help using Base SAS procedures

Double trailing behaviour

Reply
N/A
Posts: 0

Double trailing behaviour

Hello,

Can you please clarify when input with double trailing sign is released from the buffer (I'm using SAS 9.2)?

In SAS Help it says:

SAS releases the record that is held by a double trailing @

immediately if the pointer moves past the end of the input record

immediately if a null INPUT statement executes (input);

when the next iteration of the DATA step begins if an INPUT statement with a single trailing @ executes later in the DATA step: (input @);

BUT it seems to me that the record is also released from the buffer when an input
(different than null input and without a single trailing) executes later in DATA step.

consider this example, where I expected to have more than 2 observations in the data set, but it's not the case (the data set has only 2 observations):

data test;
infile datalines _infile_=try;
retain try;
put "BEFORE " try;
input a b c @@ ;
put "BETWEEN " try;
input d e ;
put "AFTER " try;
datalines;
1 2 3 4 5 6 7 8 567 308 12
12 890 456 0987 8765 5
;

Thank you,
Marius
Super Contributor
Super Contributor
Posts: 3,174

Re: Double trailing behaviour

That is true because you are executing the second INPUT which is coded differently, with no trailing "@@" specification. Also, if you expect multiple observations, then you must perform explicit OUTPUT statements executions in your code, as revealed in your post.

Scott Barry
SBBWorks, Inc.
N/A
Posts: 0

Re: Double trailing behaviour

Thank you, Scott.

So the true statement should be:

SAS releases the record that is held by a double trailing @

immediately if a null INPUT statement executes (input) ; OR AN INPUT WITHOUT ENDING WITH SINGLE OR DOUBLE TRAILING SIGN

Is this correct?

Marius
Super Contributor
Super Contributor
Posts: 3,174

Re: Double trailing behaviour

You must treat each statement individually, as documented. So yes, unless you specify another INPUT statement with some specified syntax, the "@@" will hold it with the next DATA step pass. And so if you code another INPUT statement (one or more actually) then the behavior will follow based on the later statement(s) defined -- which means that you could code another statement with another double or single or no trailing "@" to achieve some specific behavior, as desired.

Refer to the SAS Language DOC for each of the different types of coding techniques available.

And, also don't forget about the explicit OUTPUT statement as compared to coding none.

Scott Barry
SBBWorks, Inc.
Contributor
Posts: 44

Re: Double trailing behaviour

is there any possibility of reading x value 9 and y value missing here.

with missover option: compatability issues

with truncover option ; inifinite loop

with shorter records in input, we are able use missover and getting the results. I need the same kind of option in this case.

program

data pairs;

infile datalines truncover;

input X Y @@ ;

datalines;

1 2 5 7 9

;

run;

;

Respected Advisor
Posts: 3,777

Re: Double trailing behaviour

Double trailing @@ and MISSOVER are incomparable INFILE statement options.

If you want this to work as I think you do you can add a . for the missing value or use EOF option to resolve the LOSTCARD.

data pairs;
   infile datalines eof=eof;
   input X Y @@ ;
   eof: output;
  
datalines;
1 2 5 7 9
;;;;
   run;
Contributor
Posts: 44

Re: Double trailing behaviour

Thanks a lot . very very helpful answer.

Contributor
Posts: 44

Re: Double trailing behaviour

hi,

could you pls help me in this.

Frequent Contributor
Posts: 137

Re: Double trailing behaviour

Hi John @

Master

Can you please explain why this is failing and the fix when the data has many records. I understand EOF will fail the first time and flow over default behaviour takes effect.

/* Not properly executing*/

data pairs;

   infile datalines eof=eof;

   input X Y @@ ;

   eof: output;

   datalines;

1 2 5 7 9

2 3 4 5 6

;;;;

   run;

By the way, I have begin to read and understand(try) each and every post of yours in communities here, but i am unable to do an easy seach to all your posts on SAS -L.  I'd appreciate if you could share.

Many Thanks,

Charlotte

Respected Advisor
Posts: 3,777

Re: Double trailing behaviour

It depends on what is "correct".  What do you expect the result should be.  The program pairs 9 from line 1 and 2 from line 2.  and "incorrectly" outputs missing for both X and Y when everything is Paried.

Perhaps this is more correct.

data pairs;
   infile datalines eof=eof;
   input X Y @@;
   output;
  
return;
   eof:
   
if not missing(x) then output;
  
datalines;
1 2 5 7 9
2 3 4 5 6
;;;;
   run;

On SAS-L I've used two different gmail ids datanull and iebupdte.

Frequent Contributor
Posts: 137

Re: Double trailing behaviour

Hi, Thank you again. This expected result is to take the missing value without having to jump to the next line and read 2 pairing with 9 to complete a full pair in each observation. Desired results:

1  2

5  7

9  .

2 3

4  5

6 .

and so on please.

the latest program results of yours is:

1  2

5  7

9  2 /* to be corrected

3  4

5  6

Super User
Posts: 9,688

Re: Double trailing behaviour

Hi Charlotte,

Long time no see . What is up to you now ?

@@ can't do that . You need a special technique :  truncover + do while() .

data pairs;
   infile datalines truncover;
   input X Y @;
   do while (X ne . or Y ne .)     ;
    output;
    input X Y @;
   end;
   datalines; 
1 2 5 7 9
2 3 4 5 6
;;;;
   run;
 

Xia Keshan

Frequent Contributor
Posts: 137

Re: Double trailing behaviour

Hi Xia, Thank you so much for the courtesy and that's very kind of you. I took some time off as it has begun to get sunny and warmer, so went for a nice sunny holiday in Southern Europe. Well, got burnt though Smiley Happy  I only got back to work this week. Thanks as always and ever for all your help. I will never ever forget each one and will always value them, I promise!. I have just started learning SAS seriously and of course I would reach out to you here or offline directly every-time I run into some emergency needing your help when it matters at work.

Thanks for the solution Xia. I remember you telling me you were starting to get busy. Well, in that case I will only bother you for help during the weekends or late evenings at your convenience Smiley Happy.

I hope you are doing well and all's well in Beijing.

Peace,

Charlotte 

Super User
Posts: 9,688

Re: Double trailing behaviour

Thanks Charlotte. I admired you have holiday . I have nothing but busy things to do .

Best

Xia Keshan

Ask a Question
Discussion stats
  • 13 replies
  • 563 views
  • 3 likes
  • 6 in conversation