Building models with SAS Enterprise Miner, SAS Factory Miner, SAS Visual Data Mining and Machine Learning or just with programming

How to create multiple dataset from one dataset?

Reply
Regular Contributor
Posts: 218

How to create multiple dataset from one dataset?

Can anyone tell me what would be the code for creating multiple dataset from one dataset in one data step?

Example: I have the following info dataset

Name  City          Country

John   New York  USA

Albert Toronto      Canada

Alice  Sydney      Australia

I want to create 3 dataset called USA, Canada and Australia from info dataset above. I tried the following way, but it's not working:

data usa canada australia;

set info;

if country='usa' then output usa;

if country='Canada' then output Canada;

if country='Australia' then output Australia;

run;

can anyone help please. Thanks.

Community Manager
Posts: 2,955

Re: How to create multiple dataset from one dataset?

Here's an article that I wrote recently:

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

Be sure to read the comments, as several other experts have weighed in with improvements.

Chris

PROC Star
Posts: 7,474

Re: How to create multiple dataset from one dataset?

I seem to recall someone already answering this last week. One of your records shows the country as USA, but your if statement is looking for usa.

Community Manager
Posts: 2,955

Re: How to create multiple dataset from one dataset?

Here's the other thread:

With some of the spam activity, we've seen some people add messages more than once because messages by brand new users are moderated.  We've been trying to weed out the duplicates, but some still slip through.

Chris

Trusted Advisor
Posts: 1,301

Re: How to create multiple dataset from one dataset?

Consider whether you really need to split this dataset of if you are better off processing using BY or CLASS statements.

Ask a Question
Discussion stats
  • 4 replies
  • 354 views
  • 0 likes
  • 4 in conversation