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

Im reading some data from a file where the data is in the format 01DEC2010 which actually is the format date9 in SAS. I must read the data from the file and create a table specifiying that the format must be DATE9 but when i try to do so, at my table there is only a "." at the date columnn.

here is the sintax im using:

data maria;

infile 'C:\Users\Cesar\Desktop\tpnote\ssd.dat';

input idvol $ 1-7  @40 datevol DATE9.   @64 totalpass 65-67 @68 poidscargo 69-73;

run;

and here are some lines from the file:

IA112000000112SFOHNDJetCruise LF810001DEC1999 4  19  31 171 255 61300 79077
IA018040000018SFOSEAJetCruise SF100001DEC1999 4  10       123 150 10300 13287
IA029010000029SFOHNLJetCruise LF520002DEC1999 5  13  24 138 207 47400 61146

Can someone help me please?

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Actually there are tabs before the date so the date is NOT in column 40.

If you are using the INFILE option EXPANDTABS then the date will start in column 41.

IA112000000112SFOHNDJetCruise LF8100    01DEC1999 4  19  31 171 255 61300 79077

IA018040000018SFOSEAJetCruise SF1000    01DEC1999 4  10       123 150 10300 13287

IA029010000029SFOHNLJetCruise LF5200    02DEC1999 5  13  24 138 207 47400 61146

Plus the second line is not going to align for reading the later columns.  Since they are separated by spaces anyway I recommend replacing the missing values with period and use list mode input.

IA112000000112SFOHNDJetCruise LF8100    01DEC1999 4  19  31 171 255 61300 79077

IA018040000018SFOSEAJetCruise SF1000    01DEC1999 4  10   . 123 150 10300 13287

IA029010000029SFOHNLJetCruise LF5200    02DEC1999 5  13  24 138 207 47400 61146

View solution in original post

4 REPLIES 4
data_null__
Jade | Level 19

Need more information notes from log.  When I copy your records to an editor there are two '0a'x between LF8100 and 01DEC1999 by default SAS will use '0a' as new line.  So  datevol ain't @40.

overmar
Obsidian | Level 7

cesartiburcio,

I think the problem is that you are trying to tell it to input a date without specifying some information beforehand. To get the format to be read in correctly and applied I think you will need to specify a length, informat, and format as well as the input statement. Below is some code that should import it correctly.

data maria;

length idvol $7. datevol 8 totalpass 3 poidscargo 5;

informat idvol $7. datevol date9. totalpass BEST3. poidscargo BEST5.;

format idvol $7. datevol date9. totalpass BEST3. poidscargo BEST5.;

infile 'C:\Users\Cesar\Desktop\tpnote\ssd.dat';

input @1 idvol $1-7  @40 datevol date9. @64 totalpass BEST3. @68 poidscargo BEST5.;

run;

Also make sure that the pointers are going to the right places. When I pulled your data off of your post, the date actually started at 38, but it may have just been the way that I copied and pasted.

Hope this helps

Tom
Super User Tom
Super User

Actually there are tabs before the date so the date is NOT in column 40.

If you are using the INFILE option EXPANDTABS then the date will start in column 41.

IA112000000112SFOHNDJetCruise LF8100    01DEC1999 4  19  31 171 255 61300 79077

IA018040000018SFOSEAJetCruise SF1000    01DEC1999 4  10       123 150 10300 13287

IA029010000029SFOHNLJetCruise LF5200    02DEC1999 5  13  24 138 207 47400 61146

Plus the second line is not going to align for reading the later columns.  Since they are separated by spaces anyway I recommend replacing the missing values with period and use list mode input.

IA112000000112SFOHNDJetCruise LF8100    01DEC1999 4  19  31 171 255 61300 79077

IA018040000018SFOSEAJetCruise SF1000    01DEC1999 4  10   . 123 150 10300 13287

IA029010000029SFOHNLJetCruise LF5200    02DEC1999 5  13  24 138 207 47400 61146

cesartiburcio
Calcite | Level 5

Yes that was the only problem. the column is the column 41. thanks

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!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 2484 views
  • 6 likes
  • 4 in conversation