BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
RyanMcKay
Calcite | Level 5

I am trying to use code from a sas help page to import the same file class.txt. But sas doesn't recognise the delimiter when I try for some reason. I can get it to import properly with a data step, but I'm confused why I'm getting a different log/result for the same code and file

 

Here is the log from the sas help center

     infile 'C:\userid\pathname\Class.txt' delimiter='09'x MISSOVER DSD lrecl=32767
18 ! firstobs=5 ;
19          informat Name $7. ;
20          informat Gender $1. ;
21          informat Age $3. ;
22          format Name $7. ;
23          format Gender $1. ;
24          format Age $3. ;
25       input
26                   Name  $
27                   Gender  $
28                   Age  $
29       ;
30       if _ERROR_ then call symputx('_EFIERR_',1);  /* set ERROR detection macro variable */
31       run;

and my log 

 

 infile '/folders/myfolders/practice data/IMPORT DATA/class.txt' delimiter='09'x MISSOVER DSD lrecl=32767 firstobs=5 ;
 96                informat Name_____Gender___Age $20. ;
 97                format Name_____Gender___Age $20. ;
 98             input
 99                         Name_____Gender___Age  $
 100            ;
 101            if _ERROR_ then call symputx('_EFIERR_',1);  /* set ERROR detection macro variable */
 102            run;
The import code is 
proc import datafile='/folders/myfolders/practice data/IMPORT DATA/class.txt' 
            out=class
            dbms=dlm
            replace;

	   datarow=5;

     delimiter='09'x;
run;
proc print data=class;
run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Someone/something has converted the file. The tabs have been replaced by spaces. That is why your original program did not work.

View solution in original post

7 REPLIES 7
Sleo007
Obsidian | Level 7
Firstly, from the log it seems like you have no spaces between your variables in the informat & format statements, so that could be 1 problem. They also don't match the names from the SAS help file, as there are no underscores in the help file. If your variable names all have that underscore in them, I would clean the file prior to importing it, especially if it's only 3 variables. Additionally, the '09'x refers to tab-delimited data. Since your variables have underscores in them, it makes me wonder if they are separated by tabs or spaces. Have you opened the file to check the data prior to importing it?
RyanMcKay
Calcite | Level 5
Thank you!

This is what's in the file

Name Gender Age
Joyce F 11
Thomas M 11
Jane F 12
Louise F 12
James M 12
John M 12
Robert M 12
Alice F 13
Barbara F 13
Jeffery M 13
Carol F 14
Judy F 14
Alfred M 14
Henry M 14
Jenet F 15
Mary F 15
Ronald M 15
William M 15
Philip M 16
Sleo007
Obsidian | Level 7
Okay, your values are separated by spaces. Have you tried dlm=" " ? That is the notation for the space delimiter.
Tom
Super User Tom
Super User

The log you posted does not agree with the lines of text you posted later.  In particular the fact that it made this variable name:

Name_____Gender___Age

shows a couple of things about the data in the file.  First is does NOT use tabs as the delimiter. Most likely it just has spaces.  And also that unlike your example lines of data you posted there are five characters between the e in name and the G in gender. 

 

There is no need to use PROC IMPORT to read such a simple file.  Just write your own data step.

data class ;
  infile 'C:\userid\pathname\Class.txt' truncover firstobs=2;
  length name $7 gender $1 age 8;
  input name gender age;
run;
RyanMcKay
Calcite | Level 5

Thanks Tom,

The spaces between e and g are there, they have just been formatted out when I posted the comment here

This is from the sas help page

"Example 3: Importing a Tab-Delimited File

This example imports the following tab-delimited file and creates a temporary SAS data set named Work.Class."

Tom
Super User Tom
Super User

Someone/something has converted the file. The tabs have been replaced by spaces. That is why your original program did not work.

RyanMcKay
Calcite | Level 5
I think I have figured it out. In the older versions of the 9.4 book it shows one variable as Name_____Gender___Age after importing. Maybe the practice file "class.txt" hasn't been updated to match the book, so it doesn't format the way the book shows.

Welcome to the Certification Community

 

This is a knowledge-sharing community for SAS Certified Professionals and anyone who wants to learn more about becoming SAS Certified. Ask questions and get answers fast. Share with others who are interested in certification and who are studying for certifications.To get the most from your community experience, use these getting-started resources:

Community Do's and Don'ts
How to add SAS syntax to your post
How to get fast, helpful answers

 

Why Get SAS Certified.jpg

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
  • 7 replies
  • 1196 views
  • 1 like
  • 3 in conversation