BookmarkSubscribeRSS Feed
Tim123
Calcite | Level 5

I am trying to output natural numbers that are not divisible by 3 and 5 on SAS data step.

data x;

k=0;

a=0;

do until(k>=70);

output;

a= Mod(k,3)~=0 and a= Mod(k,5)~=0;

k=k+1;

end;

drop k;

run;

This is obviously not correct!

2 REPLIES 2
ballardw
Super User

Maybe a tad simplier:

data want;

     do a=0 to 100;

     if mod(a,3) ne 0 and mod(a,5) ne 0 then output;

     end;

run;

    

Your a= Mod(k,3)~=0 and a= Mod(k,5)~=0; was assigning a logical value to A based on comparing the first mod to 0 which yields a 0 or 1 depending true, then comparing the current value of a to mod(k,5) and then the 0. Since the logical comparisons always yield 0 or 1 in SAS terms you weren't getting what you want. And the specific operations generally result in False

PGStats
Opal | Level 21

You weren't that far :

data x;

do k = 0 to 70;

    if Mod(k, 3) ~= 0 and Mod(k, 5) ~= 0 then output;

    end;

run;

PG

PG

sas-innovate-2024.png

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.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 784 views
  • 0 likes
  • 3 in conversation