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

SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!
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

SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!
FriedEgg
SAS Employee

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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1589 views
  • 0 likes
  • 4 in conversation