BookmarkSubscribeRSS Feed
mlogan
Lapis Lazuli | Level 10

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.

4 REPLIES 4
ChrisHemedinger
Community Manager

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

Become an Explorer! Join SAS Analytics Explorers to learn and complete challenges that earn rewards!
art297
Opal | Level 21

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.

ChrisHemedinger
Community Manager

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

Become an Explorer! Join SAS Analytics Explorers to learn and complete challenges that earn rewards!
FriedEgg
SAS Employee

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

Catch up on SAS Innovate 2026

Nearly 200 sessions are now available on demand with the SAS Innovate Digital Pass.

Explore Now →
How to choose a machine learning algorithm

Use this tutorial as a handy guide to weigh the pros and cons of these commonly used machine learning algorithms.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 2559 views
  • 0 likes
  • 4 in conversation