## Print number in Decreasing order without proc sort

Solved
Occasional Contributor
Posts: 12

# 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: 10,279

## Re: Print number in Decreasing order without proc sort

[ Edited ]
``````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
How to convert datasets to data steps
How to post code

All Replies
PROC Star
Posts: 1,283

## Re: Print number in Decreasing order without proc sort

Why are you not allowed to use proc sort?

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: 10,279

## Re: Print number in Decreasing order without proc sort

[ Edited ]
``````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
How to convert datasets to data steps
How to post code
Occasional Contributor
Posts: 12

## Re: Print number in Decreasing order without proc sort

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: 10,279

## Re: Print number in Decreasing order without proc sort

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
How to convert datasets to data steps
How to post code
☑ This topic is solved.

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