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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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