BookmarkSubscribeRSS Feed
harveysarah0
Calcite | Level 5

data albums;
input Name : Artist : ReleaseDate : ;
cards;
Album,Artist,ReleaseDate,TotalCertifiedCopies,ClaimedSales,Genre
Thriller,Michael Jackson,"November 30, 1982",46.3,65,Pop
Back in Black,AC/DC,"July 25, 1980",26.1,50,Rock
The Dark Side of the Moon,Pink Floyd,"March 1, 1973",24.2,45,Rock
The Bodyguard: Original Soundtrack Album,Various Artists,"November 17, 1992",27.4,44,Soundtrack
Bat Out of Hell,Meat Loaf,"October 21, 1977",21.5,43,Rock
Their Greatest Hits (1971-1975),Eagles,"February 17, 1976",32.2,42,Rock
Saturday Night Fever: The Original Movie Sound Track,Various Artists,"November 15, 1977",20.6,40,Soundtrack
Rumours,Fleetwood Mac,"February 4, 1977",27.9,40,Rock
Come On Over,Shania Twain,"November 4, 1997",29.6,39,Country
Led Zeppelin IV,Led Zeppelin,"November 8, 1971",29.0,37,Rock
Bad,Michael Jackson,"August 31, 1987",21.3,34,Pop
Alanis Morissette,Jagged Little Pill,"June 13, 1995",24.4,33,Rock
Falling Into You,Celine Dion,"March 8, 1996",20.2,32,Pop
"Sgt. Pepper's Lonely Hearts Club Band",The Beatles,"May 26, 1967",13.1,32,Rock
Hotel California,Eagles,"December 8, 1976",21.5,32,Rock
Dangerous,Michael Jackson,"November 26, 1991",17.6,32,Pop
Dirty Dancing,Various Artists,"August 4, 1987",17.9,32,Soundtrack
21,Adele,"January 24, 2011",25.3,31,Pop
"Let's Talk About Love",Celine Dion,"November 14, 1997",19.3,31,Pop
1,The Beatles,"November 13, 2000",22.6,31,Rock
The Immaculate Collection,Madonna,"November 9, 1990",19.4,30,Pop
Abbey Road,The Beatles,"September 26, 1969",14.4,30,Rock
Born in the U.S.A.,Bruce Springsteen,"June 4, 1984",19.6,30,Rock
Brothers in Arms,Dire Straits,"May 13, 1985",17.7,30,Rock
Titanic: Music from the Motion Picture,James Horner,"November 18, 1997",18.1,30,Soundtrack
Metallica,Metallica,"August 12, 1991",21.2,30,Metal
Nevermind,Nirvana,"September 24, 1991",16.7,30,Grunge
The Wall,Pink Floyd,"November 30, 1979",17.6,30,Rock
Supernatural,Santana,"June 15, 1999",20.5,30,Rock
Appetite for Destruction,"Guns N' Roses","July 21, 1987",21.6,30,Metal
;

 

I am coming up with multiple errors when trying to load this file into SAS. 

6 REPLIES 6
harveysarah0
Calcite | Level 5

Load the comma delimited TopGrossingAlbumsR.txt file posted on Blackboard into

SAS. This contains data on the top 30 highest selling albums according to Wikipedia. It

includes the name of the album, the artist of the album, the release date of the album, the

number of certified copies by the RIAA, the number of copies sold, and the album genre.

Make sure release date is treated as a date by using an informat.

 

This is the step provided that I am supposed to do.

fdsaaaa
Obsidian | Level 7

Are you doing an assignment? with all due respect you will not learn anything if you keep getting other people to supply answers for you . What have you tried so far? What do you think the problem is ? Have you researched what an informat is ? 

ballardw
Super User

If this is a comma separate file I would suggest 1) use the import wizard or proc import and 2) examine the log for the code generated by the import step. If things aren't as desired then copy the code from the log to the editor and modify as needed.

 

Your posted code shows no informat information so all of the variables on the input statement would be read as numeric (default in SAS) and generates LOTS of invalid data messages.

 

If you write code and run it. Look at the LOG. It will tell you a lot about what happens.

ed_sas_member
Meteorite | Level 14

Hi @harveysarah0 

 

The INPUT statement should contain the names of the columns.

In you case, it should be Album,Artist,ReleaseDate,TotalCertifiedCopies,ClaimedSales,Genre.

CARDS should contains values for each observation.

 

  • As values are operated by commas in the CARDS, you need to specify it to SAS -> you can use an INFILE statement to do this such as: 
 INFILE CARDS DLM=",";
  • In the INPUT statement, you need to specify the type of each variable (character / numeric) -> if the variable is character, you just need to add a $ just after the name. Eg Album $
  • By default, SAS will read character values on 8 bytes -> as you have longer values, you need to specify to SAS to read them up to the delimiter instead of up to the 8th character. You can use an informat to do this (please not the colon in the syntax) : e.g. INPUT Album:$50 Artist:$50 ...

 

Finally, you may encounter an issue with the ReleaseDate variable as its values are in a WORDDATE. informat such as "November 30, 1982". The problem is that this format contains a "comma", which is a delimiter.

Can't you use another delimiter?

 

Hope this helps.

Best,

Tom
Super User Tom
Super User

The DSD infile option will allow the INPUT statement to properly parse those data lines.

ed_sas_member
Meteorite | Level 14

Hi @harveysarah0 

 

 

As mentionned by @Tom (Thank you @Tom !), the DSD option will enable you to manage the release date variable properly, as this option specifies that when data values are enclosed in quotation marks, delimiters within the value are treated as character data.

 

The following code should work:

data albums;
	infile cards dlm="," dsd;
	input Album:$50. Artist:$50. ReleaseDate:anydtdte. TotalCertifiedCopies ClaimedSales Genre:$20.;
	format ReleaseDate worddate.;
	cards;
Thriller,Michael Jackson,"November 30, 1982",46.3,65,Pop
Back in Black,AC/DC,"July 25, 1980",26.1,50,Rock
The Dark Side of the Moon,Pink Floyd,"March 1, 1973",24.2,45,Rock
The Bodyguard: Original Soundtrack Album,Various Artists,"November 17, 1992",27.4,44,Soundtrack
...
Appetite for Destruction,"Guns N' Roses","July 21, 1987",21.6,30,Metal
;

Best,

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 775 views
  • 2 likes
  • 5 in conversation