03-30-2015 03:33 PM
I request your valuable time in explaining the application of Input statement in a do loop with one simple and another medium complex example to help me understand the concept. The reason why I am asking is because, despite reading the documentation I am not comprehending the subject very well. Also, the documentation being so long (with too many options), by the time I got through till the end of it, I seem to lose my way.
I'd appreciate if you could illustrate your example with a single trailing @ and double trailing @@ in the do loop. Thanks for the favor!.
03-30-2015 03:40 PM
To give you relevant input, please describe what issue drives you to use this concept. Chances are otherwise that our explanation will not make it clearer for your...
03-30-2015 03:43 PM
The double trailing at is to hold the INPUT line for the next iteration of the "data step loop" sometime called "observation loop".
Ruminate on that for a bit.
03-30-2015 03:53 PM
Hi John, Thanks, Yeah I got that. so If there is a dataline like:
input x @@; *will output like
3 * hope my understanding is right?
Now, my difficulty in understanding lies when such input statement are used in a do loop like
do i= 1 to some_number(or some variable);
input x @@;
This is where I am stumped. It's doesn't seem as easy as understanding the use set statement in a do loop. Sorry for the bother
03-30-2015 04:38 PM
You can do your own testing and you will learn more. Run this and consider why it gives 80 obs.
03-30-2015 04:42 PM
Now try this version.
03-30-2015 05:11 PM
John wow, That's a brain teaser. You are giving me true blonde moments
1. Result of the 1st code tests:
I experimented running them again and again. Then I inserted a space between the letters and removed the informat. This seem to just output 6 obs. Still lost in the logic why 80obs, although it seems it's got something to do the position of the cursor?
2. Result of 2nd code: very neat
/*first input gets the record into the input buffer, and does it hold there until the 2nd input executes? but the explicit output should override the implicit output before step boundary is reached right, oh my god I am knocked out*./
03-30-2015 05:32 PM
cards is unbuffered, 80 obs because line length is fixed for cards at 80...
input x $1. @@;
if missing(x) then stop;
Message was edited by: FriedEgg for correctness
03-30-2015 05:45 PM
HI Matt/John, Very very Interesting. thank you so much for your time, nevertheless, like you said I will have to test over and over to get my understanding bingo. It's 11pm here in Liverpool, England and I am so knackered that my eyes are barely open. I will put my best effort tomorrow and get back to you should I still find it difficult to understand.
03-31-2015 07:42 AM
Actually CARDS data is un-buffered which is why you can't use INFILE statement option END. The default record length is fixed that is why the example program reads 80 columns to EOF.
03-30-2015 06:17 PM
Let's change #2 slightly to illustrate how single trailing at works for this example with multiple records.
03-31-2015 07:29 AM
Good morning John /Matt/Tom, Thank you so very much for your time and patience. It seems to me that before I ask any follow up question and irritate you, let me continue testing your code reading between the statements in detail and get some understanding, so that my questions will sound wiser. Please forgive me. I really am trying my level best to not ask to be spoon fed or annoy you. I'm rather irritated with myself. I will keep this thread open for another day or two and will come back to you with relatively good questions having some level of home work done.
Have a nice day,
04-01-2015 12:36 PM
Hi, I know I'm late to this party, but I ran across these examples of a double trailing @ (@@) in a SAS/STAT example and thought I would post it here for you.
do loop with input and @@ example with PROC LOGISTIC (basically, they are reading and rereading the input file to make the number of cases they need for the procedure)
and here's an example without a DO loop Base SAS(R) 9.4 Procedures Guide: Statistical Procedures, Third Edition where 4 variables for Iris data are read over and over again out of the input file (sometimes people have this type of data, where "pairs" of measurements are automatically added to a file by some kind of device or process. In this case, every 4 data points in the input file belong to 1 observation. So if you run the code you will get 50 obs because there are 50 "sets" of 4 datapoints read to build each obs.
04-01-2015 01:21 PM
Your first example is not very good because the the data step reads all the data in one iteration. @ would suffice.
The second example is classic @@.
03-30-2015 06:46 PM
You can think of SAS as having a column pointer and a line pointer.
An input statement without any trailing @ or @@ will increment the line pointer and set the column pointer to 1.
An input statement with @@ also will prevent SAS from doing the same at the end of the data step.
DO loop really doesn't have much to do with understanding how it works. Consider that you could always just code a do loop as a series of statements.
do i=1 to 3 ; input x @ ; output; end;
Is the same as
input x @; output;
input x @; output;
input x @; output;