BookmarkSubscribeRSS Feed
AppleHaart64
Calcite | Level 5

Can someone explain to me what is wrong with my code and how to possibly fix it, codebook is attached. I am trying to match the start and end points for the variables stated in my SAS programming but it never comes out properly. My SAS results have a lot of missing values even though according to the txt file there should be information there.

DATA AExp;
INFILE "...\...\....\....\H4\AssessorExport.txt";
	INPUT OwnerName1 $ 0017-0166 OwnerName2 $ 0167-0316 OwnerName3 $ 0317-0466 PropStNum 0487-0521 PropAddrUnit 0527-0536 
	PropAddress 0537-0596 $ LandValue 1218-1237 BuildingValue 1238-1257 AppraisedValue 1258-1277 AssessedValue 1278-1297 
	Sale1Year 1566-1569 Sale1Month 1570-1571 Sale1Day 1572-1573 Sale2Year 1644-1647 Sale2Month 1648-1649 Sale2Day 1650-1651;
	RUN;
proc print data = AExp (obs = 100);
	RUN;

 Error.PNGTXTSnap.PNGResultsView.PNG

3 REPLIES 3
PaigeMiller
Diamond | Level 26

@AppleHaart64 wrote:

Can someone explain to me what is wrong with my code and how to possibly fix it, codebook is attached. I am trying to match the start and end points for the variables stated in my SAS programming but it never comes out properly.

DATA AExp;
INFILE "...\...\....\....\H4\AssessorExport.txt";
	INPUT OwnerName1 $ 0017-0166 OwnerName2 $ 0167-0316 OwnerName3 $ 0317-0466 PropStNum 0487-0521 PropAddrUnit 0527-0536 
	PropAddress 0537-0596 $ LandValue 1218-1237 BuildingValue 1238-1257 AppraisedValue 1258-1277 AssessedValue 1278-1297 
	Sale1Year 1566-1569 Sale1Month 1570-1571 Sale1Day 1572-1573 Sale2Year 1644-1647 Sale2Month 1648-1649 Sale2Day 1650-1651;
	RUN;
proc print data = AExp (obs = 100);
	RUN;

You haven't told us what is wrong with your code, all we know (we can assume) is that the results are not right. But we don't know what the right answer should be. We don't have your data, we don't have your knowledge, and so we need a lot more information in order to help.

 

Also, most of us will not download Microsoft Office documents as they can be a security threat. Instead of attaching files, just include the necessary information in your reply as plain text or images included via the "Insert Photos" icon.

--
Paige Miller
ballardw
Super User

"Wrong with code" is awful vague.

Are there errors in the log?: Post the code and log in a code box opened with the "</>" to maintain formatting of error messages.

No output? Post any log in a code box.

Unexpected output? In this case copy and paste a few lines of the text file to read into a text box opened with the </> icon.

 

Note that your codebook has this very important line:

Also enclosed is a complete description of the comma delimited file or CSV file which the
Assessor of Property has made available.

That means that the FIXED column approach, i.e. a "start and end point" to read you are attempting is just plain wrong. Commas separate the values unless you have modified the file and that is on you.

 

CSV files should have the delimiter option on the INFILE statement such as DLM=',' to use commas. If there is any text in long fields that may include commas then add the DSD option to the Infile as well.

Then you should provide descriptors for the variables such as an informat or length and not provide columns to read. If the value in the document says it is ALPHANUMERIC then provide a LENGTH statement with the length in the document as the length of the variable. That should be the maximum length needed but in a CSV file shorter values would not use all of the columns and so your fixed column approach would read part of the following value into the previous.

 

For values labeled as DECIMAL just leave them alone.

The values that say they are dates and appear a M/D/YYYY you want to use a MMDDYY10. informat and assign a SAS date format either MMDDYY10. to match the input, or YYMMDD10. or DATE9. so folks don't have to guess which is month and which is day with values like 03/05/2021. Specify the informat with the : modifier to avoid some of the issues with likely short values of 1 digit month or 1 digit day. Something like: Sale_date :mmddyy10.  on the input.

Tom
Super User Tom
Super User

The letter at the front of the codebook says the file is comma delimited.

So ignore the STARTS and ENDS column in the back of the codebook.  Instead just pay attention to the LENGTH and TYPE columns.

So use the DSD and TRUNCOVER option on the INFILE statement.

Define the LENGTH of the variables (use 8 as the length for all of the numeric variables).

If you define them in the order they appear in the file then the INPUT statement can just use a position based variable list.

So your program will look like this.  Fill in the rest of the variables.

DATA AExp;
  INFILE "...\...\....\....\H4\AssessorExport.txt"  dsd truncover ;
  length GIDLink $16 OwnerName1-OwnerName3 $150 
     PropStNum PropStPfx $10
     PropStName $35
   ...
     CalcAcres MapAcres DeedAcres LUCode 8
     NeighborhoodCode $12 
     LandValue 8
  ...
     CurrentUse $4
  ;
  input GIDLink -- CurrentUse ;
run;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 3 replies
  • 473 views
  • 0 likes
  • 4 in conversation