BookmarkSubscribeRSS Feed
SkyMoCo
Calcite | Level 5

I've started moving doing more of my own coding vs using enterprise guide and I have a puzzling issue.   I have the same input statement, that works just great with the input in a datalines, but when I try and use a and INFILE, sas complains about data format issues.   I'm running SAS 9.2 on AIX.  I am doing all my edits on the unix box so I doubt it's some sort of unix/dos formatting issue.   I'm a little puzzled.   If I read it all in as strings and convert it also seems to work fine, but that's more work when I have 500 or so fields.

This works fine:

OPTIONS DATESTYLE=MDY;

data &TEMP_DS;

  format timeStamp dateampm22. ;

  input tdate mmddyy11. hourStamp adjCount comma8.;

  timeStamp=dhms(tdate,hourStamp,30,0);

  keep timeStamp hourStamp adjCount;

label

        timeStamp = "TimeStamp"

        adjCount = "Adjucation Count"

;

datalines;

01/01/2010 3   321

01/01/2010  4  335

01/01/2010  5  376

01/01/2010  6  383

01/01/2010  7  385

;

But when this same data is in a file and try to use:

INFILE "/user_data/adjdata.txt"

                MISSOVER

                DSD

;

I get:

NOTE: Invalid data for hourStamp in line 1 12-19.

RULE:     ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0                   

1         01/01/2010  3   321 19

timeStamp=. dateStamp=. tdate=18263 hourStamp=. adjCount=. _ERROR_=1 _N_=1

6 REPLIES 6
allurai0412
Fluorite | Level 6

hi ,

use truncover and pad ...in the follwing step..??

INFILE "/user_data/adjdata.txt"

                truncover

                DSD;

input tdate mmddyy11. @13  hourStamp @16 adjCount comma8.;

SkyMoCo
Calcite | Level 5

That doesn't seem to help.   I still get the same error.

NOTE: Invalid data for hourStamp in line 1 12-19.

RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0

1         01/01/2010  3   321 19

timeStamp=. dateStamp=. tdate=18263 hourStamp=. adjCount=. _ERROR_=1 _N_=1

What does "Invalid data" mean, is there any more detail somewhere?

allurai0412
Fluorite | Level 6

hi,

when you are pasting the data from 'datalines ' in to txt file .....some wrong  alligment for the  'tdate' and 'hourstamp'...is happening .. while importing it will give wrong...allingment...please check this

or

eg : please delete the first row of your data and check...

i have not observed any errors with following code ..

Note : i have adjusted the alligment of first row !!

data TEMP_DS;
infile "C:\Users\galax_allu\Desktop\adjdata.txt" truncover pad;
OPTIONS DATESTYLE=MDY;
  format timeStamp dateampm22. ;
   input tdate mmddyy11. hourStamp adjCount comma8.;

  timeStamp=dhms(tdate,hourStamp,30,0);

  keep timeStamp hourStamp adjCount;

label

        timeStamp = "TimeStamp"

        adjCount = "Adjucation Count"

;

run;

Regards

Allu

..

Tom
Super User Tom
Super User

PAD is redundant if you are using TRUNCOVER.

allurai0412
Fluorite | Level 6

thanks Tom..

Tom
Super User Tom
Super User

Why are you using DSD option?  That will make it attempt to read the lines as if the fields were separated with commas.  So you read the first 11 columns because of the explicit informat length. So then it reads the rest of the line (columns 12 to 19 in this case) as one field and the embedded space makes it an invalid number.

Also do not use MISSOVER as that will set values to missing when only part of it is available on the same line. Use the TRUNCOVER option instead so when you attempt to read past the end of the line if keeps the values that are there.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

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
  • 6 replies
  • 866 views
  • 0 likes
  • 3 in conversation