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;
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.