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

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
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

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
FriedEgg
SAS Employee

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

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