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

I'm doing a typical look ahead read when the input data has only one observation I get the WARNING:.  My program still works I just don't want to be warned.

 

data class;
   set sashelp.class;
   output;
   stop;
   run;

data next;
   set class end=eof;
   if not eof then set class(firstobs=2 keep=name rename=name=nextname);
   output;
   call missing(nextname);
   run;
proc print;
   run;

 

 

 

34         data next;
35            set class end=eof;
36            if not eof then set class(firstobs=2 keep=name rename=name=nextname);
WARNING: FIRSTOBS option > number of observations in WORK.CLASS.
37            output;
38            call missing(nextname);
39            run;

NOTE: There were 1 observations read from the data set WORK.CLASS.
NOTE: The data set WORK.NEXT has 1 observations and 6 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

I don't know of any option to suppress that warning.

You could perhaps use a view to create the look_ahead data.

data class;
   set sashelp.class (obs=1);
run;

data look_ahead / view=look_ahead;
  set class ;
  if _n_ > 1;
  keep=name;
  rename name=nextname;
run;

data next;
   set class end=eof ;
   if not eof then set look_ahead ;
   output;
   call missing(nextname);
run;

Or if it doesn't mess up other things (like FIRST. processing) you could just read the first observation twice and throw away the extra one.

data next;
   set class(obs=1) class end=eof;
   if not eof then set class(keep=name rename=(name=nextname));
   if _n_ > 1 then output;
   call missing(nextname);
run;

 

View solution in original post

3 REPLIES 3
Tom
Super User Tom
Super User

I don't know of any option to suppress that warning.

You could perhaps use a view to create the look_ahead data.

data class;
   set sashelp.class (obs=1);
run;

data look_ahead / view=look_ahead;
  set class ;
  if _n_ > 1;
  keep=name;
  rename name=nextname;
run;

data next;
   set class end=eof ;
   if not eof then set look_ahead ;
   output;
   call missing(nextname);
run;

Or if it doesn't mess up other things (like FIRST. processing) you could just read the first observation twice and throw away the extra one.

data next;
   set class(obs=1) class end=eof;
   if not eof then set class(keep=name rename=(name=nextname));
   if _n_ > 1 then output;
   call missing(nextname);
run;

 

data_null__
Jade | Level 19

 


@Tom wrote:

I don't know of any option to suppress that warning.

You could perhaps use a view to create the look_ahead data.

data class;
   set sashelp.class (obs=1);
run;

data look_ahead / view=look_ahead;
  set class ;
  if _n_ > 1;
  keep=name;
  rename name=nextname;
run;

data next;
   set class end=eof ;
   if not eof then set look_ahead ;
   output;
   call missing(nextname);
run;

Or if it doesn't mess up other things (like FIRST. processing) you could just read the first observation twice and through away the extra one.

data next;
   set class(obs=1) class end=eof;
   if not eof then set class(keep=name rename=(name=nextname));
   if _n_ > 1 then output;
   call missing(nextname);
run;

 


Thanks Tom, excellent use of view and turning the problem around.  

Ksharp
Super User
John King, 
Can you add one more obs at the end of CLASS ?


data class;
   set sashelp.class (obs=1);
run;

data copy_class;
 set class(keep=name) end=last;
 output;
 if last then do;
  call missing(name);
  output;
 end;
run;

data next;
   set class end=eof;
   if not eof then set copy_class(firstobs=2 keep=name rename=name=nextname);
   output;
   call missing(nextname);
   run;


hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 3 replies
  • 2155 views
  • 3 likes
  • 3 in conversation