## How to display even observations without using mod function, if statement and loops

Solved
Occasional Contributor
Posts: 10

# How to display even observations without using mod function, if statement and loops

Hi!!! please help me out to get output for this input without using mod function, if statement and loops

Input:

110 111 101 113 109

108 105 101 109 101

122 123 124 125 101

127 128 129 130 103

102 103 101 104 107

106 107 101 109 103

101 109 107 109 107

111 101 999 105 101

Output:

108 105 101 109 101

127 128 129 130 103

106 107 101 109 103

111 101 999 105 101

Accepted Solutions
Solution
‎08-04-2013 10:03 PM
Super User
Posts: 8,127

## Re: How to display even observations without using mod function, if statement and loops

Is this a game?  Do I get a cookie if I win?

data have;

input x1-x5 ;

cards;

110 111 101 113 109

108 105 101 109 101

122 123 124 125 101

127 128 129 130 103

102 103 101 104 107

106 107 101 109 103

101 109 107 109 107

111 101 999 105 101

run;

data want;

getone:

set have;

run;

data _null_;

set want;

put (x1-x5) ( ;

run;

108 105 101 109 101

127 128 129 130 103

106 107 101 109 103

111 101 999 105 101

NOTE: There were 4 observations read from the data set WORK.WANT.

All Replies
Super User
Posts: 6,785

## Re: How to display even observations without using mod function, if statement and loops

Sounds like a short homework assignment, so it's possible you may need to look up and study some of the tools used here:

data want;

do _n_=2 to _nobs_ by 2;

set have nobs=_nobs_ point=_n_;

output;

end;

stop;

run;

Good luck.

Occasional Contributor
Posts: 10

## Re: How to display even observations without using mod function, if statement and loops

Thanks Astouding its working fine.

But I need code to get output without using mod function, if statements and loops.

Super User
Posts: 8,127

## Re: How to display even observations without using mod function, if statement and loops

If your source is a text file (or inline card images) then just skip a line in the INPUT statement.

data want;

input / x1-x5 ;

cards;

110 111 101 113 109

108 105 101 109 101

122 123 124 125 101

127 128 129 130 103

102 103 101 104 107

106 107 101 109 103

101 109 107 109 107

111 101 999 105 101

run;

Super Contributor
Posts: 312

## Re: How to display even observations without using mod function, if statement and loops

DATA WANT;

SET HAVE;

IF _N_/2 = INT(_N_/2);

RUN;

Posts: 5,541

## Re: How to display even observations without using mod function, if statement and loops

There are many ways to interpret that question. So I will choose the easiest one . Here you are: no MOD, no loop, no IF :

data _null_;

input;

input;

put _infile_;

datalines;

110 111 101 113 109

108 105 101 109 101

122 123 124 125 101

127 128 129 130 103

102 103 101 104 107

106 107 101 109 103

101 109 107 109 107

111 101 999 105 101

;

PG

PG
Occasional Contributor
Posts: 10

## Re: How to display even observations without using mod function, if statement and loops

I am newbie to SAS. I tried your code but its not working.

Posts: 5,541

## Re: How to display even observations without using mod function, if statement and loops

It is for me. What error do you get?

PG
Posts: 3,852

## Re: How to display even observations without using mod function, if statement and loops

What about the "data step loop".  Can't do much without loops.

Posts: 5,541

## Re: How to display even observations without using mod function, if statement and loops

If the data resides in a dataset then you have to resort to conditionals other than IF and conditions not involving MOD such as :

data have;
input;
line = _infile_;
datalines;
110 111 101 113 109
108 105 101 109 101
122 123 124 125 101
127 128 129 130 103
102 103 101 104 107
106 107 101 109 103
101 109 107 109 107
111 101 999 105 101
;

data want(where=(line ne "DROP"));
set have;
line = choosec(1+(round(_n_, 2) = _n_), "DROP", line);
run;

data want2;
set have;
select (round(_n_, 2));
when (_n_) output;
otherwise;
end;
run;

PG

PG
Solution
‎08-04-2013 10:03 PM
Super User
Posts: 8,127

## Re: How to display even observations without using mod function, if statement and loops

Is this a game?  Do I get a cookie if I win?

data have;

input x1-x5 ;

cards;

110 111 101 113 109

108 105 101 109 101

122 123 124 125 101

127 128 129 130 103

102 103 101 104 107

106 107 101 109 103

101 109 107 109 107

111 101 999 105 101

run;

data want;

getone:

set have;

run;

data _null_;

set want;

put (x1-x5) ( ;

run;

108 105 101 109 101

127 128 129 130 103

106 107 101 109 103

111 101 999 105 101

NOTE: There were 4 observations read from the data set WORK.WANT.

Posts: 5,541

## Re: How to display even observations without using mod function, if statement and loops

Tom, you certainly deserve that cookie! - PG

PG
Posts: 3,167

## Re: How to display even observations without using mod function, if statement and loops

It took me a while to figure out that implicit "return" in action. Thanks, Tom.

Occasional Contributor
Posts: 10

## Re: How to display even observations without using mod function, if statement and loops

Thanks a lot. You really deserve the cookie .

Thanks a lot to everyone for wonderful ideas.

Posts: 3,167

## Re: How to display even observations without using mod function, if statement and loops

No MOD, No IF and No Loop:

 proc sql; select * from have where round(monotonic()/2)=monotonic()/2; quit;
🔒 This topic is solved and locked.