BookmarkSubscribeRSS Feed
Sama1
Calcite | Level 5
Hi

I’m recently started learning SAS so need help with do loops

A dataset of 1000 observations , use a do loop to output every 100 observations in to new dataset

Thanks
3 REPLIES 3
Kurt_Bremser
Super User

Use the mod() function on the automatic variable _N_ in a subsetting if.

To get more information, do google searches on

SAS mod function

SAS _n_ variable

SAS subsetting if

Astounding
PROC Star

To do this is easy.  But to do it using a DO loop is not as easy, and not really a "beginner's" problem.  For example:

 

data want;

do _n_=100 to _nobs_ by 100;

   set have point=_n_ nobs=_nobs_;

   output;

end;

stop;

run;

 

Accomplishing this without a DO loop is relatively easy and a more appropriate problem:

 

data want;

set have;

if mod(_n_, 100) = 0;

run;

 

Even so, most beginners would find this method challenging.

Sama1
Calcite | Level 5
Thank you

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!

How to Concatenate Values

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.

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
  • 3 replies
  • 713 views
  • 0 likes
  • 3 in conversation