BookmarkSubscribeRSS Feed
Tom
Super User Tom
Super User

Yes, re-read the text file and ignore the results of the PROC IMPORT.  You can read them one by one or try to use the trick on the other example data step to read all of the files at once into one large dataset.  To read all of the files with one data step they must have the fields in the same order on the lines.  So if the structure has changed over the years you will want to read them one by one (or group the like files together anyway.)

 

If you write your own data step to read the text files then you can be assured that the variables are all created exactly the same.  This means that you can combine the dataset if you create them separately.  It also means you can prevent variables from being define with the wrong type (numeric or character) or wrong length.

 

You can use the results of the PROC IMPORT to help you figure out how to define the variables in your program.  But you probably will want to refer to the definition of the variables as published on the source website.  Again some of these fields appear to have only digits in them but they are not NUMBERS.  They are identifiers.  It will probably be useful to define such variables as character.  That is the problem with using PROC IMPORT. A text file has no place to store the attributes of the variables so PROC IMPORT just guesses what to do based the values it checks.

Blandine
Obsidian | Level 7

I modified your code and this is what I used. One thing I realized is that although it imported everything the data are not were it's supposed to be for example Year_built_027 variable is showing other number than the year. 

 

data want ;
length filen $256 ;
infile 'C:\Users\bmrg2\Box Sync\Mizzou 2019\Research\SAS Code\Blandine Data\RBI2020\ILLINOIS\IL_Added_inspection_year\*.txt' dsd truncover filename=filen;
input @;
if filen ne lag(filen) then input ;
input STRUCTURE_NUMBER_008 YEAR_BUILT_027 MAINTENANCE_021 OWNER_022 ADT_029 SERVICE_ON_042A SERVICE_UND_042B STRUCTURE_KIND_043A STRUCTURE_TYPE_043B
DECK_STRUCTURE_TYPE_107 DECK_COND_058 SUPERSTRUCTURE_COND_059 SUBSTRUCTURE_COND_060 PERCENT_ADT_TRUCK_109 SCOUR_CRITICAL_113 Inspection_year :$20. ;
filename=filen ;
run;
Blandine
Obsidian | Level 7

Yes it is

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 18 replies
  • 5475 views
  • 4 likes
  • 5 in conversation