BookmarkSubscribeRSS Feed
MarkWik
Quartz | Level 8

i'm failing to understand the do while(1) construct, 1 in () does it mean anything in the expression without referencing a variable name in the do while(expression)

data w ( keep = date time cond species vers hdr x1 - x9 ) ;

           format date date7. time time12.2 ;

           infile cards truncover eof = fini ;

           input @'date ' datec $char9.

                  @'time ' time :time11.

                / @'Condition: ' cond $char20.

                / @'Species: ' species $8.

                / @'version: ' vers $8.

                / @'information: ' hdr $20.

                / ;

           /* will the software produce bad dates in 2+ years??? */

           date = input ( compress ( datec,'-'), date7. ) ;

          do while ( 1 ) ; /* what does this expression mean?*/

              input ( x1 - x9 ) ( :$20. ) ;

              output ;

           end ;

        return ;

        fini:

        return ;

        cards ;

        date 10-jan-95 time 05:20.36.44

        Condition: blah, blah, blah,

        Species: 4LA

        Software version: xxx.xx

        Other header information: aaaa.a bbbbb.b

        operators-who-collected-the-data...

          x y x az el ra speed direction, etc.

          x y x az el ra speed direction, etc.

          x y x az el ra speed direction, etc.

          x y x az el ra speed direction, etc.

          x y x az el ra speed direction, etc.

        ;

4 REPLIES 4
data_null__
Jade | Level 19

The expression evaluated is 1, TRUE.  It means do forever.  The thing you need to know is why doesn't it actually do forever.  For that look at INFILE statement options EOF= and UNBUFFERED.

art297
Opal | Level 21

The do while(1) will simply keep reading and outputting your x1-x9 values until it reaches an end of file. It is simply saying do while(true)

Yes, you will run into problems if your date ever contains a 4 digit year.

And, if your times are really in the format shown in your example, they will have to be modified before input as well.

e.g.,

data w ( keep = date time cond species vers hdr x1 - x9 ) ;

           informat datec $char11.;

           informat timec $char11.;

           format date date7.;

           format time time12.2 ;

           infile cards truncover eof = fini ;

           input @'date ' datec

                  @'time ' timec

                / @'Condition: ' cond $char20.

                / @'Species: ' species $8.

                / @'version: ' vers $8.

                / @'information: ' hdr $20.

                / ;

           /* will the software produce bad dates in 2+ years??? */

           date = input ( compress ( datec,'-'), anydtdte9. ) ;

           substr(timec,index(timec,'.'),1) = ':';

           time=input(timec,time11.);

          do while ( 1 ) ; /* what does this expression mean?*/

              input ( x1 - x9 ) ( :$20. ) ;

              output ;

           end ;

        return ;

        fini:

        return ;

        cards ;

        date 10-jan-2014 time 05:20.36.44

        Condition: blah, blah, blah,

        Species: 4LA

        Software version: xxx.xx

        Other header information: aaaa.a bbbbb.b

        operators-who-collected-the-data...

          x y x az el ra speed direction, etc.

          x y x az el ra speed direction, etc.

          x y x az el ra speed direction, etc.

          x y x az el ra speed direction, etc.

          x y x az el ra speed direction, etc.

        ;

MarkWik
Quartz | Level 8

cool. Thanks Art and DN. Is there any specific document or link can you point me to for more and complete information on such do loop constructs particularly mentioning different ways to write expressions to use in do loop constructs unlike the convention as well as like using set inside a do loop, do _n_= as index variable and so on ? I have read through some on some docs found online but my grasping to this kind isn't quick:(  Sorry for the bother

Mark

art297
Opal | Level 21

Mark: Post an example of the data you are trying to read and it will be a lot easier to point you in the right direction.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 4 replies
  • 556 views
  • 6 likes
  • 3 in conversation