BookmarkSubscribeRSS Feed
marianhabesland
Calcite | Level 5

The raw data displayed below contains values for the following variables:

  • League (Character)
  • Team (Character)
  • Wins (Numeric)
  • Losses (Numeric) 

Write a DATA step that reads in the value for League, tests it, keeps only observations with a value of ‘American’, and produces an output data set containing all 4 variables.

 

This is my code so far:

data WORK.Illus;
infiles datalines delimiter = ' ';
input League $8. @;
if League = 'American';
input Team $18.
Wins 2
Losses 2;
datalines;
National New York Mets 19 12
American Toronto Blue Jays 19 13
American Boston Red Sox 17 12
National St Louis Cardinals 13 11

;

 

This is all I get in my table. What can I do to actually get the data I need in the table?

Screen Shot 2017-09-26 at 18.02.48.png

 

2 REPLIES 2
WarrenKuhfeld
Ammonite | Level 13
Remove both 2's. You do not want to read from column 2.
Wins 2
Losses 2;
Tom
Super User Tom
Super User

Post code and especially the data using the Insert Code or Insert SAS code buttons in the editor.

Otherwise important information, like which columns the data is in, whether there is anything to make the end of the team name, etc. will be lost because the forum will format your post into paragraphs.

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

Develop Code with SAS Studio

Get started using SAS Studio to write, run and debug your SAS programs.

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
  • 2 replies
  • 1070 views
  • 0 likes
  • 3 in conversation