DATA Step, Macro, Functions and more

Print number in Decreasing order without proc sort

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 12
Accepted Solution

Print number in Decreasing order without proc sort

I have to print all the numbers less than 500 which is divisible by 7 in decreasing order WITHOUT using PROC SORT.


Accepted Solutions
Solution
‎11-15-2016 09:52 AM
Super User
Posts: 7,866

Re: Print number in Decreasing order without proc sort

[ Edited ]
Posted in reply to abhaykumar
data test;
do i = 500 to 1 by -1;
  if mod(i,7) = 0 then output;
end;
run;

proc print data=test noobs;
run;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
PROC Star
Posts: 768

Re: Print number in Decreasing order without proc sort

Posted in reply to abhaykumar

Why are you not allowed to use proc sort? Smiley Happy

 

Are you allowed to use proc sort inside a call execute statement in the data step? 

Occasional Contributor
Posts: 12

Re: Print number in Decreasing order without proc sort

To find some other method to solve this problem .
Occasional Contributor
Posts: 12

Re: Print number in Decreasing order without proc sort

Proc sort is not been taught in class yet.
Solution
‎11-15-2016 09:52 AM
Super User
Posts: 7,866

Re: Print number in Decreasing order without proc sort

[ Edited ]
Posted in reply to abhaykumar
data test;
do i = 500 to 1 by -1;
  if mod(i,7) = 0 then output;
end;
run;

proc print data=test noobs;
run;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Occasional Contributor
Posts: 12

Re: Print number in Decreasing order without proc sort

Posted in reply to KurtBremser
Thank You sir, I was trying this way but I was not knowing about "By -1" thing. and I guess we can increase or decrease by any value by using "by -/+n" step, right?
Super User
Posts: 7,866

Re: Print number in Decreasing order without proc sort

Posted in reply to abhaykumar

abhaykumar wrote:
Thank You sir, I was trying this way but I was not knowing about "By -1" thing. and I guess we can increase or decrease by any value by using "by -/+n" step, right?

Correct. You can even use values with fractions.

Like

data test;
do i = 10 to 0 by -1.5;
  output;
end;
run;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
☑ This topic is solved.

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

Discussion stats
  • 6 replies
  • 300 views
  • 2 likes
  • 3 in conversation