BookmarkSubscribeRSS Feed
Ronein
Meteorite | Level 14

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

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 3 replies
  • 436 views
  • 0 likes
  • 4 in conversation