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;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.