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;
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;
Someone/something has converted the file. The tabs have been replaced by spaces. That is why your original program did not work.
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;
Someone/something has converted the file. The tabs have been replaced by spaces. That is why your original program did not work.
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
Ready to level-up your skills? Choose your own adventure.