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;
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;
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.
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
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.