Getting text file into SAS University Edition

Accepted Solution Solved
Reply
New Contributor
Posts: 4
Accepted Solution

Getting text file into SAS University Edition

I put the following code into SAS University Edition. I'm trying to create a temporary dataset called work.HALT_comma and use an infile statement to bring up the data. Here is what I have:

 

 data work.HALT_comma;
 infile '/folders/myfolders/Halt_comma.txt' dlm=',';
 input interview_date, fruit_juice, sweet_drink, fruit, veggies, sweets, hgt_ft, hgt_in, weight, asthma, depression, htn, ev_smk, exercise;
 run;
 
I got the following error:
 
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
55
56 data work.HALT_comma;
57 infile '/folders/myfolders/Halt_comma.txt' dlm=',';
58 input interview_date, fruit_juice, sweet_drink, fruit, veggies, sweets, hgt_ft, hgt_in, weight, asthma, depression, htn,
_
22
76
58 ! ev_smk, exercise;
ERROR 22-322: Syntax error, expecting one of the following: [, {.
 
ERROR 76-322: Syntax error, statement will be ignored.
 
59 run;
 
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.HALT_COMMA may be incomplete. When this step was stopped there were 0 observations and 0 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.02 seconds
 
60
61 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
73
 
Can anyone help? Thank you so much
 
Kelsey
 
 

Accepted Solutions
Solution
‎02-07-2016 06:39 PM
Super User
Posts: 17,840

Re: Getting text file into SAS University Edition

The errors are pretty specific:

 

NOTE: Invalid data for interview_date in line 1 1-10.
NOTE: Invalid data for exercise in line 1 39-47.

Interview date appears to be in the format 12/01/2014, ddmmyy10, so you can specify that in an informat so it reads properly.

Exercise appears possibly as text, ie bicycling, so you can add the $ after the variable to allow it to read in properly. It also looks like you have 15 variables in your dataset, but your input statement is only counting 14 variables. 

 

data work.HALT_comma;
informat interview_date ddmmyy10.;
infile '/folders/myfolders/Halt_comma.txt' dlm=',';
input interview_date fruit_juice sweet_drink fruit veggies sweets hgt_ft hgt_in weight asthma depression htn ev_smk exercise $;
run;

View solution in original post


All Replies
Super User
Posts: 17,840

Re: Getting text file into SAS University Edition

The variables listed in your input statement should be space delimited, not comma delimited. You specify the comma delimited portion in the infile statement, correctly, but may also want to consider adding the DSD and TRUNCOVER option. It helps avoid errors in reading in data.

 

 input interview_date fruit_juice sweet_drink fruit veggies sweets hgt_ftn hgt_in  weight asthma depression htn ev_smk exercise;
New Contributor
Posts: 4

Re: Getting text file into SAS University Edition

I eliminated the commas and still got an error. Is something else wrong too?
Super User
Posts: 17,840

Re: Getting text file into SAS University Edition

What error did you get, I'm assuming it's a different one.

New Contributor
Posts: 4

Re: Getting text file into SAS University Edition

It actually worked the second time I tried it, but two of my variables did not upload and read as blank. I'm not sure what to do about that. Here is the error it gave me.

 

1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
55
56 data work.HALT_comma;
57 infile '/folders/myfolders/Halt_comma.txt' dlm=',';
58 input interview_date fruit_juice sweet_drink fruit veggies sweets hgt_ft hgt_in weight asthma depression htn ev_smk
58 ! exercise;
59 run;
 
NOTE: The infile '/folders/myfolders/Halt_comma.txt' is:
Filename=/folders/myfolders/Halt_comma.txt,
Owner Name=root,Group Name=vboxsf,
Access Permission=-rwxrwx---,
Last Modified=07Feb2016:14:37:17,
File Size (bytes)=1764
 
NOTE: Invalid data for interview_date in line 1 1-10.
NOTE: Invalid data for exercise in line 1 39-47.
RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0
1 12/01/2014,1,6,5,8,7,5,10,182,0,0,0,1,bicycling 47
interview_date=. fruit_juice=1 sweet_drink=6 fruit=5 veggies=8 sweets=7 hgt_ft=5 hgt_in=10 weight=182 asthma=0 depression=0 htn=0
ev_smk=1 exercise=. _ERROR_=1 _N_=1
NOTE: Invalid data for interview_date in line 2 1-10.
NOTE: Invalid data for exercise in line 2 38-44.
2 12/05/2014,1,9,4,9,4,5,5,140,0,0,0,0,running 44
interview_date=. fruit_juice=1 sweet_drink=9 fruit=4 veggies=9 sweets=4 hgt_ft=5 hgt_in=5 weight=140 asthma=0 depression=0 htn=0
ev_smk=0 exercise=. _ERROR_=1 _N_=2
NOTE: Invalid data for interview_date in line 3 1-10.
NOTE: Invalid data for exercise in line 3 38-41.
3 12/06/2014,1,6,7,6,6,5,6,180,0,0,0,0,none 41
interview_date=. fruit_juice=1 sweet_drink=6 fruit=7 veggies=6 sweets=6 hgt_ft=5 hgt_in=6 weight=180 asthma=0 depression=0 htn=0
ev_smk=0 exercise=. _ERROR_=1 _N_=3
NOTE: Invalid data for interview_date in line 4 1-10.
NOTE: Invalid data for exercise in line 4 38-41.
4 12/12/2014,1,1,3,6,3,5,4,241,1,0,1,1,none 41
interview_date=. fruit_juice=1 sweet_drink=1 fruit=3 veggies=6 sweets=3 hgt_ft=5 hgt_in=4 weight=241 asthma=1 depression=0 htn=1
ev_smk=1 exercise=. _ERROR_=1 _N_=4
NOTE: Invalid data for interview_date in line 5 1-10.
NOTE: Invalid data for exercise in line 5 38-41.
5 12/15/2014,1,3,4,5,2,5,2,140,0,0,0,1,none 41
interview_date=. fruit_juice=1 sweet_drink=3 fruit=4 veggies=5 sweets=2 hgt_ft=5 hgt_in=2 weight=140 asthma=0 depression=0 htn=0
ev_smk=1 exercise=. _ERROR_=1 _N_=5
NOTE: Invalid data for interview_date in line 6 1-10.
NOTE: Invalid data for exercise in line 6 38-46.
6 12/11/2014,1,9,4,6,6,5,9,154,0,0,0,1,bicycling 46
interview_date=. fruit_juice=1 sweet_drink=9 fruit=4 veggies=6 sweets=6 hgt_ft=5 hgt_in=9 weight=154 asthma=0 depression=0 htn=0
ev_smk=1 exercise=. _ERROR_=1 _N_=6
NOTE: Invalid data for interview_date in line 7 1-10.
NOTE: Invalid data for exercise in line 7 40-47.
7 12/16/2014,1,10,6,6,6,5,10,181,0,0,0,0,swimming 47
interview_date=. fruit_juice=1 sweet_drink=10 fruit=6 veggies=6 sweets=6 hgt_ft=5 hgt_in=10 weight=181 asthma=0 depression=0 htn=0
ev_smk=0 exercise=. _ERROR_=1 _N_=7
NOTE: Invalid data for interview_date in line 8 1-10.
NOTE: Invalid data for exercise in line 8 39-44.
8 01/02/2015,1,9,9,9,5,5,11,165,0,0,0,0,tennis 44
interview_date=. fruit_juice=1 sweet_drink=9 fruit=9 veggies=9 sweets=5 hgt_ft=5 hgt_in=11 weight=165 asthma=0 depression=0 htn=0
ev_smk=0 exercise=. _ERROR_=1 _N_=8
NOTE: Invalid data for interview_date in line 9 1-10.
NOTE: Invalid data for exercise in line 9 38-44.
RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0
9 02/12/2015,1,3,5,6,7,5,8,235,0,1,0,0,walking 44
interview_date=. fruit_juice=1 sweet_drink=3 fruit=5 veggies=6 sweets=7 hgt_ft=5 hgt_in=8 weight=235 asthma=0 depression=1 htn=0
ev_smk=0 exercise=. _ERROR_=1 _N_=9
NOTE: Invalid data for interview_date in line 10 1-10.
NOTE: Invalid data for exercise in line 10 38-44.
10 12/01/2014,2,9,6,6,8,5,9,135,0,1,0,1,walking 44
interview_date=. fruit_juice=2 sweet_drink=9 fruit=6 veggies=6 sweets=8 hgt_ft=5 hgt_in=9 weight=135 asthma=0 depression=1 htn=0
ev_smk=1 exercise=. _ERROR_=1 _N_=10
NOTE: Invalid data for interview_date in line 11 1-10.
NOTE: Invalid data for exercise in line 11 38-43.
11 12/04/2014,2,5,6,6,4,5,4,148,0,0,0,0,tennis 43
interview_date=. fruit_juice=2 sweet_drink=5 fruit=6 veggies=6 sweets=4 hgt_ft=5 hgt_in=4 weight=148 asthma=0 depression=0 htn=0
ev_smk=0 exercise=. _ERROR_=1 _N_=11
NOTE: Invalid data for interview_date in line 12 1-10.
NOTE: Invalid data for exercise in line 12 38-44.
12 12/09/2014,2,8,6,7,8,5,5,120,0,0,0,0,walking 44
interview_date=. fruit_juice=2 sweet_drink=8 fruit=6 veggies=7 sweets=8 hgt_ft=5 hgt_in=5 weight=120 asthma=0 depression=0 htn=0
ev_smk=0 exercise=. _ERROR_=1 _N_=12
NOTE: Invalid data for interview_date in line 13 1-10.
NOTE: Invalid data for exercise in line 13 38-44.
13 12/11/2014,2,7,5,5,6,5,5,123,0,0,0,0,running 44
interview_date=. fruit_juice=2 sweet_drink=7 fruit=5 veggies=5 sweets=6 hgt_ft=5 hgt_in=5 weight=123 asthma=0 depression=0 htn=0
ev_smk=0 exercise=. _ERROR_=1 _N_=13
NOTE: Invalid data for interview_date in line 14 1-10.
NOTE: Invalid data for exercise in line 14 39-45.
14 12/11/2014,2,2,8,9,5,5,10,137,0,0,0,0,running 45
interview_date=. fruit_juice=2 sweet_drink=2 fruit=8 veggies=9 sweets=5 hgt_ft=5 hgt_in=10 weight=137 asthma=0 depression=0 htn=0
ev_smk=0 exercise=. _ERROR_=1 _N_=14
NOTE: Invalid data for interview_date in line 15 1-10.
NOTE: Invalid data for exercise in line 15 38-46.
15 12/11/2014,2,3,6,6,2,5,3,164,0,0,0,0,bicycling 46
interview_date=. fruit_juice=2 sweet_drink=3 fruit=6 veggies=6 sweets=2 hgt_ft=5 hgt_in=3 weight=164 asthma=0 depression=0 htn=0
ev_smk=0 exercise=. _ERROR_=1 _N_=15
NOTE: Invalid data for interview_date in line 16 1-10.
NOTE: Invalid data for exercise in line 16 39-45.
16 12/18/2014,2,7,5,2,7,5,10,230,0,1,0,0,walking 45
interview_date=. fruit_juice=2 sweet_drink=7 fruit=5 veggies=2 sweets=7 hgt_ft=5 hgt_in=10 weight=230 asthma=0 depression=1 htn=0
ev_smk=0 exercise=. _ERROR_=1 _N_=16
NOTE: Invalid data for interview_date in line 17 1-10.
NOTE: Invalid data for exercise in line 17 39-47.
17 12/04/2014,3,3,5,8,8,5,10,367,0,0,1,1,bicycling 47
interview_date=. fruit_juice=3 sweet_drink=3 fruit=5 veggies=8 sweets=8 hgt_ft=5 hgt_in=10 weight=367 asthma=0 depression=0 htn=1
ev_smk=1 exercise=. _ERROR_=1 _N_=17
NOTE: Invalid data for interview_date in line 18 1-10.
NOTE: Invalid data for exercise in line 18 38-41.
18 12/11/2014,3,1,9,9,6,5,3,100,0,0,0,0,none 41
interview_date=. fruit_juice=3 sweet_drink=1 fruit=9 veggies=9 sweets=6 hgt_ft=5 hgt_in=3 weight=100 asthma=0 depression=0 htn=0
ev_smk=0 exercise=. _ERROR_=1 _N_=18
NOTE: Invalid data for interview_date in line 19 1-10.
NOTE: Invalid data for exercise in line 19 38-46.
19 12/12/2014,3,2,9,7,6,5,6,120,0,0,0,1,bicycling 46
interview_date=. fruit_juice=3 sweet_drink=2 fruit=9 veggies=7 sweets=6 hgt_ft=5 hgt_in=6 weight=120 asthma=0 depression=0 htn=0
ev_smk=1 exercise=. _ERROR_=1 _N_=19
NOTE: Invalid data for interview_date in line 20 1-10.
NOTE: Invalid data for exercise in line 20 39-45.
WARNING: Limit set by ERRORS= option reached. Further errors of this type will not be printed.
RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0
20 12/05/2014,3,10,7,9,6,5,6,190,0,1,0,1,walking 45
interview_date=. fruit_juice=3 sweet_drink=10 fruit=7 veggies=9 sweets=6 hgt_ft=5 hgt_in=6 weight=190 asthma=0 depression=1 htn=0
ev_smk=1 exercise=. _ERROR_=1 _N_=20
NOTE: 38 records were read from the infile '/folders/myfolders/Halt_comma.txt'.
The minimum record length was 41.
The maximum record length was 48.
NOTE: The data set WORK.HALT_COMMA has 38 observations and 14 variables.
NOTE: DATA statement used (Total process time):
real time 0.02 seconds
cpu time 0.03 seconds
 
 
60
61 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
73
Solution
‎02-07-2016 06:39 PM
Super User
Posts: 17,840

Re: Getting text file into SAS University Edition

The errors are pretty specific:

 

NOTE: Invalid data for interview_date in line 1 1-10.
NOTE: Invalid data for exercise in line 1 39-47.

Interview date appears to be in the format 12/01/2014, ddmmyy10, so you can specify that in an informat so it reads properly.

Exercise appears possibly as text, ie bicycling, so you can add the $ after the variable to allow it to read in properly. It also looks like you have 15 variables in your dataset, but your input statement is only counting 14 variables. 

 

data work.HALT_comma;
informat interview_date ddmmyy10.;
infile '/folders/myfolders/Halt_comma.txt' dlm=',';
input interview_date fruit_juice sweet_drink fruit veggies sweets hgt_ft hgt_in weight asthma depression htn ev_smk exercise $;
run;
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 369 views
  • 0 likes
  • 2 in conversation