DATA Step, Macro, Functions and more

How should I write the code for this delimiter problem?

Reply
New Contributor
Posts: 2

How should I write the code for this delimiter problem?

1.PNG2.PNG

As you can see, at observation 12, the value should be "DraculaSmiley Very Happyead and Loving It (1995)" for the title. However, I got what's shown in the picture above. This is my code:

 

libname perm '/home/cheok19970/Assignment';
data perm.movies;
informat MovieID 4. Title $60. Genre $50.;
infile '/home/cheok19970/Assignment/movies.dat' dlm='Smiley Indifferent';
input MovieID Title $ Genre $;
run;

Since I put colon and vertical pipe as the delimiter, the code is eliminating all the ":" and "|" in the data set. Besides, the output genre only shows one genre. How do i fix it? 

Super User
Posts: 24,026

Re: How should I write the code for this delimiter problem?

DLMSTR in the infile statement. Look it up under the INFILE documentation.

New Contributor
Posts: 2

Re: How should I write the code for this delimiter problem?

image.png

libname perm '/home/cheok19970/Assignment';
data perm.movies;
	informat MovieID 4. Title $60. Genre $50.;
	infile '/home/cheok19970/Assignment/movies.dat' dlmstr=':|';
	input MovieID Title $ Genre $;
run;

proc print data=perm.movies noobs;
run;

I'm getting weird output :/

Super User
Posts: 24,026

Re: How should I write the code for this delimiter problem?

The DLMSTR should be :: and then you need to parse GENRE out separately after, because the number of entries there are not consistent, some have 1, some have 3 genres.  Make sure to parse out the year as well. For either you can use the SCAN function.

 

There are some other data issues throughout. 

 

There's actually code on here somewhere on how to read the file properly, someone else asked this already. 

Ask a Question
Discussion stats
  • 3 replies
  • 108 views
  • 0 likes
  • 2 in conversation