DATA Step, Macro, Functions and more

Find two central observation of SAS data set.

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 12
Accepted Solution

Find two central observation of SAS data set.

[ Edited ]

I have to find  two central observations of a one character variable dataset. It has even number of observation.

dataset is :

 data dset;
infile datalines ;
input sex $ ;
datalines;
M
M
F
F
F
F
M
M
F
F
F
F
F
F
F
M
M
F
F
F
F
F
M
M
;
run;


Accepted Solutions
Solution
‎11-15-2016 12:29 PM
PROC Star
Posts: 736

Re: Find two central observation of SAS data set.

Posted in reply to abhaykumar

try this

 

data want;
   set dset nobs=nobs;
   if _N_ = nobs/2 or _N_ = nobs/2 + 1;
run;

View solution in original post


All Replies
Solution
‎11-15-2016 12:29 PM
PROC Star
Posts: 736

Re: Find two central observation of SAS data set.

Posted in reply to abhaykumar

try this

 

data want;
   set dset nobs=nobs;
   if _N_ = nobs/2 or _N_ = nobs/2 + 1;
run;
PROC Star
Posts: 736

Re: Find two central observation of SAS data set.

I have assumed that you always have an equal number of observations in your dataset Smiley Happy

Occasional Contributor
Posts: 12

Re: Find two central observation of SAS data set.

It works Smiley Happy Thank you.
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 273 views
  • 1 like
  • 2 in conversation