When using "firstobs" function on a column it creates a lookahead column because of which empty cells are created(Number depends on the argument used in the lookahead function) at the end of the column. Is there any way I can define the value to be filled in that empty cell?
Show us your code.
data WORK.test;
merge
WORK.sample_table
WORK.sample_table (firstobs=2 keep=SerialNumber rename=(SerialNumber=_SerialNumber));
/* further processing */
run;
After executing the above code 1 empty cell will get created in the last row of the column, now I want to define a certain value to be filled in that empty/null cell. How can I achieve that?
See if you can use this as a template
data have;
input x @@;
datalines;
1 2 3 4 5
;
data want;
merge have end=z
have(firstobs = 2 rename=x=_x);
if z then _x = 999;
run;
I think you need to provide example data AND full code.
The code you show will basically duplicate the value for all rows and nothing should be "blank" unless you reset the variable values.
I suspect you may actually be running code with OBS=1 on a data set with two rows of data like this:
data have; input x @@; datalines; 1 2 ; data want; merge have have(obs = 1 rename=(x=y)); run;
There is functionally no difference between
data want; merge have have (rename=(var=newvar)) ; run; /*or*/ data want; merge have have (firstobs=1 rename=(var=newvar)) ; run;
From the documentation:
Firstobs Specifies the first row in a data source that SAS processes.
So when you say Firstobs=1 then you are defaulting to using all observations starting with the first, in other words the default behavior of using all the values.
Did you try my code above?
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.