BookmarkSubscribeRSS Feed
vincentgoh88
Fluorite | Level 6

Hi, 

 

How to create a looping for code below if I wish to loop 10 times and output 10 times?Besides using data step, is there any other simple method using proc? 

 

data S1 S2 ... S10;

set set0;

 

if book = 'A1' then output A1;

else if book 'A2' then output A2;

...

else if book 'A10' then output A10;

 

run; 

 

 

 

Thanks

 

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

The Data Step sounds like the ideal tool for this job so why do you want to do it another way?

vincentgoh88
Fluorite | Level 6

I wish to learn other way if there is any. 

Reeza
Super User

Here are examples of other ways. 

I will point out the general advice though: 99% of the time this is a bad idea.

 

https://blogs.sas.com/content/sasdummy/2015/01/26/how-to-split-one-data-set-into-many/

http://www.sascommunity.org/wiki/Split_Data_into_Subsets

Read to the bottom of the second link to find other options including call execute, macros and such. 


@vincentgoh88 wrote:

Hi, 

 

How to create a looping for code below if I wish to loop 10 times and output 10 times?Besides using data step, is there any other simple method using proc? 

 

data S1 S2 ... S10;

set set0;

 

if book = 'A1' then output A1;

else if book 'A2' then output A2;

...

else if book 'A10' then output A10;

 

run; 

 

 

 

Thanks

 


 

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1339 views
  • 0 likes
  • 3 in conversation