BookmarkSubscribeRSS Feed
Ronein
Onyx | Level 15

Hello

I want to create a new data set that start from observation  3 and take 4 observations.

However in the reslut I get only 2 

data ttt;
input ID x;
1 10
2 20
3 30
4 40
5 50
6 60
7 70
8 80
9 90
10 100
;
run;
data new;
    set ttt(firstobs=3 obs=4);
run;
3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

As the Firstobs= Options Doc says: "When the FIRSTOBS= data set option specifies a starting point for processing, the OBS= data set option specifies an ending point. The two options are often used together to define a range of observations to be processed. "

 

Therefore, do this instead

 

data new;
    set ttt(firstobs=3 obs=6);
run;
Kurt_Bremser
Super User

obs= does not specify the number of observations to be read, but a specific observation number up to which the data is read. So you get observation #3 and observation #4.

novinosrin
Tourmaline | Level 20

Hi @Ronein  Easy way to understand is

 

FIRSTOBS=  specifies the first observation to read. 

 

OBS= Last observation to read. 

 

What perhaps confused you is the thought OBS = is the number of observations of read however it is the last observation to read. Also, FirstOBs should never be greater than Obs at all times. Hope this helps

CFC_SAS_Communities_400x225.jpgCFC_SAS_Communities_400x225.jpg

Call for content now open!

It's your turn to help shape SAS Innovate 2027. Share your expertise and inspire the SAS community.

Submit your proposal →

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
  • 2020 views
  • 0 likes
  • 4 in conversation