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
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;
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;
@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.
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;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.