I have to print all the numbers less than 500 which is divisible by 7 in decreasing order WITHOUT using PROC SORT.
data test;
do i = 500 to 1 by -1;
if mod(i,7) = 0 then output;
end;
run;
proc print data=test noobs;
run;
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?
data test;
do i = 500 to 1 by -1;
if mod(i,7) = 0 then output;
end;
run;
proc print data=test noobs;
run;
@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;
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 25. 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.