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
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;
link getone;
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.
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.
Thanks Astouding its working fine.
But I need code to get output without using mod function, if statements 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;
DATA WANT;
SET HAVE;
IF _N_/2 = INT(_N_/2);
RUN;
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
Thanks PGStats for reply.
I am newbie to SAS. I tried your code but its not working.
It is for me. What error do you get?
What about the "data step loop". Can't do much without 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
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;
link getone;
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.
Tom, you certainly deserve that cookie! - PG
It took me a while to figure out that implicit "return" in action. Thanks, Tom.
Thanks a lot. You really deserve the cookie .
Thanks a lot to everyone for wonderful ideas.
No MOD, No IF and No Loop:
proc sql; | ||
select * from have | ||
where round(monotonic()/2)=monotonic()/2; | ||
quit; |
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: