BookmarkSubscribeRSS Feed
Saurabh_Rana
Obsidian | Level 7

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?

6 REPLIES 6
Saurabh_Rana
Obsidian | Level 7

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?

PeterClemmensen
Tourmaline | Level 20

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;
ballardw
Super User

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.

 

Saurabh_Rana
Obsidian | Level 7
My bad. I am using firstobs=2 in my code

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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