BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Rambo_UK
Calcite | Level 5

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

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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.

View solution in original post

14 REPLIES 14
Astounding
PROC Star

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.

Rambo_UK
Calcite | Level 5

Thanks Astouding its working fine.

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

Tom
Super User Tom
Super User

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;

Scott_Mitchell
Quartz | Level 8

DATA WANT;

SET HAVE;

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

RUN;

PGStats
Opal | Level 21

There are many ways to interpret that question. So I will choose the easiest one Smiley Happy. 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
Rambo_UK
Calcite | Level 5

Thanks PGStats for reply.

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

PGStats
Opal | Level 21

It is for me. What error do you get?

PG
data_null__
Jade | Level 19

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

PGStats
Opal | Level 21

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
Tom
Super User Tom
Super User

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.

PGStats
Opal | Level 21

Tom, you certainly deserve that cookie! - PG

PG
Haikuo
Onyx | Level 15

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

Rambo_UK
Calcite | Level 5

Thanks a lot. You really deserve the cookie Smiley Wink.

Thanks a lot to everyone for wonderful ideas.

Haikuo
Onyx | Level 15

No MOD, No IF and No Loop:

proc sql;
    select * from have
  where round(monotonic()/2)=monotonic()/2;
  quit;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 14 replies
  • 2069 views
  • 6 likes
  • 7 in conversation