Hi there,
I'm having trouble to import the iris.txt dataset below.
I've spent way more than a couple of hours and tried some approaches, none of them worked.
Here's a print of what my dataset looks like:
I've tried a couple of ways.
1) With proc import
FILENAME REFFILE '/folders/myfolders/data/iris.txt';
PROC IMPORT DATAFILE=REFFILE
DBMS=DLM
OUT=work.iris;
DELIMITER='09'x; *the hexadecimal representation of Tab in ASCII;
GETNAMES=no;
datarow=2;
GUESSINGROWS=100;
RUN;
2) I also tried with infile:
data work.iris;
infile '/folders/myfolders/isye6501/iris.txt'
delimiter='09'x
missover
firstobs=2
DSD
lrecl = 32767;
format obs;
format Sepal_Length;
format Sepal_Width;
format Petal_Length;
format Petal_Width;
format Species $25.;
input
obs
Sepal_Length
Sepal_Width
Petal_Length
Petal_Width
Species $
;
run;
Both failed to load the data (the first one loads one column and the second returns all missing values =/).
Can someone give me some help?
I've attached the data.
It seems to be a fixed column format so this works.
data want;
infile 'C:\Users\fareeza.khurshed\Downloads\iris.txt' truncover termstr=CRLF;
length obs var1-var4 8. species $12.;
input @1 obs @14 var1 @26 var2 @39 var3 @51 var4 @54 species ;
run;
Add an option before proc import.
options validvarname=any;
proc import ...............
Can you attach the file?
Sure thing
I had attached the dataset, but let me attach the code too.
It seems to be a fixed column format so this works.
data want;
infile 'C:\Users\fareeza.khurshed\Downloads\iris.txt' truncover termstr=CRLF;
length obs var1-var4 8. species $12.;
input @1 obs @14 var1 @26 var2 @39 var3 @51 var4 @54 species ;
run;
Hi Reeza,
Thank you so much, that worked well.
Just one question: how do I delete the second row (while keeping header /1st row) of my output? Because it's currently looking like this:
firstobs = 2.
FILENAME REFFILE '/folders/myfolders/data/iris.txt';
PROC IMPORT DATAFILE=REFFILE
DBMS=DLM
OUT=work.iris;
DELIMITER='09'x; *the hexadecimal representation of Tab in ASCII;
GETNAMES=no;
datarow=2;
GUESSINGROWS=max;
RUN;
Does the above work? If not, post the full log please. In your text file it has numbers in the first column - are those line numbers or are they actually in the data?
Hi Reeza,
Nope, that piece of code did not work either.
I have 2 problems with this file: the variables' names have dots and the first column is missing a header (it's the observations column, starting in row 2). So my idea now is maybe start from the second column and ignore headers, but I'm unsure how to do that. All the resources I read online did not show how to do this.
Here's the log for the piece of code you sent me:
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
72
73 *ISYE 6501 - Homework #02 Question 4.2;
74 * use proc import to assist you importing the file iris.txt;
75 %let path=/folders/myfolders/isye6501; *defining work directory;
76 libname hmw "&path";
NOTE: Libref HMW was successfully assigned as follows:
Engine: V9
Physical Name: /folders/myfolders/isye6501
76 ! *assigning a library to store files;
77
78
79 FILENAME REFFILE '/folders/myfolders/isye6501/iris.txt';
80
81 PROC IMPORT DATAFILE=REFFILE
82 DBMS=DLM
83 OUT=work.iris;
84 DELIMITER='09'x; *the hexadecimal representation of Tab in ASCII;
85 GETNAMES=no;
86 datarow=2;
87 GUESSINGROWS=max;
88 RUN;
NOTE: Unable to open parameter catalog: SASUSER.PARMS.PARMS.SLIST in update mode. Temporary parameter values will be saved to
WORK.PARMS.PARMS.SLIST.
89 /**********************************************************************
90 * PRODUCT: SAS
91 * VERSION: 9.4
92 * CREATOR: External File Interface
93 * DATE: 20JUN18
94 * DESC: Generated SAS Datastep Code
95 * TEMPLATE SOURCE: (None Specified.)
96 ***********************************************************************/
97 data WORK.IRIS ;
98 %let _EFIERR_ = 0; /* set the ERROR detection macro variable */
99 infile REFFILE delimiter='09'x MISSOVER DSD firstobs=2 ;
100 informat VAR1 nlnum32. ;
101 format VAR1 nlnum12. ;
102 input
103 VAR1
104 ;
105 if _ERROR_ then call symputx('_EFIERR_',1); /* set ERROR detection macro variable */
106 run;
NOTE: The infile REFFILE is:
Filename=/folders/myfolders/isye6501/iris.txt,
Owner Name=root,Group Name=vboxsf,
Access Permission=-rwxrwx---,
Last Modified=15 de janeiro de 2018 12h36min50s,
File Size (bytes)=9964
NOTE: 150 records were read from the infile REFFILE.
The minimum record length was 64.
The maximum record length was 64.
NOTE: The data set WORK.IRIS has 150 observations and 1 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.01 seconds
150 rows created in WORK.IRIS from REFFILE.
NOTE: WORK.IRIS data set was successfully created.
NOTE: The data set WORK.IRIS has 150 observations and 1 variables.
NOTE: PROCEDURE IMPORT used (Total process time):
real time 0.17 seconds
cpu time 0.13 seconds
107
108
109 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
122
I appreciate your help!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.