DATA Step, Macro, Functions and more

WARNING: FIRSTOBS option > number of observations in WORK.CLASS.

Accepted Solution Solved
Reply
Respected Advisor
Posts: 3,867
Accepted Solution

WARNING: FIRSTOBS option > number of observations in WORK.CLASS.

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

Accepted Solutions
Solution
‎10-27-2017 03:32 PM
Super User
Super User
Posts: 8,279

Re: WARNING: FIRSTOBS option > number of observations in WORK.CLASS.

[ Edited ]
Posted in reply to data_null__

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


All Replies
Solution
‎10-27-2017 03:32 PM
Super User
Super User
Posts: 8,279

Re: WARNING: FIRSTOBS option > number of observations in WORK.CLASS.

[ Edited ]
Posted in reply to data_null__

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;

 

Respected Advisor
Posts: 3,867

Re: WARNING: FIRSTOBS option > number of observations in WORK.CLASS.

 


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.  

Super User
Posts: 10,850

Re: WARNING: FIRSTOBS option > number of observations in WORK.CLASS.

Posted in reply to data_null__
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;


☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 296 views
  • 3 likes
  • 3 in conversation