Help using Base SAS procedures

log Error in format

Reply
N/A
Posts: 0

log Error in format

Kindly could you see the code below and suggest whts wrong in it:-

data projects;
options nodate pageno=1 linesize=80 pagesize=60;
input Projid startdate date9. enddate date9.;
Duration=enddate-startdate;
datalines;
398 17oct1997 02nov1997
942 22jan1998 10mar1998
167 15dec1999 15feb2000
250 04jan2001 11jan2001
;

proc print data=projects;
format startdate enddate date9.;
title 'Days Between Project Start and Project End';
run;

reagrds,
Kriti
Frequent Contributor
Posts: 106

Re: log Error in format

Posted in reply to deleted_user
When referring to a "log Error" it would be most helpful to post the relevant log parts as well.
(Just from a quick glance I can't see anything wrong with your code. Only thing I would change: move the options statement ahead of the data step).
N/A
Posts: 0

Re: log Error in format

Posted in reply to Robert_Bardos
Hello Robert,

Many thanks for the reply. I get the error as:-

NOTE: Invalid data for enddate in line 235 14-22.
RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----
235 398 17oct1997 02nov1997
Projid=398 startdate=13804 enddate=. Duration=. _ERROR_=1 _N_=1
NOTE: Invalid data for enddate in line 236 14-22.
236 942 22jan1998 10mar1998
Projid=942 startdate=13901 enddate=. Duration=. _ERROR_=1 _N_=2
NOTE: Invalid data for enddate in line 237 14-22.
237 167 15dec1999 15feb2000
Projid=167 startdate=14593 enddate=. Duration=. _ERROR_=1 _N_=3
NOTE: Invalid data for enddate in line 238 14-22.
238 250 04jan2001 11jan2001
Projid=250 startdate=14979 enddate=. Duration=. _ERROR_=1 _N_=4
NOTE: Missing values were generated as a result of performing an operation on
missing values.
Each place is given by: (Number of times) at (Line)Smiley SadColumn).
4 at 233:17

Best Regards,
kriti
Frequent Contributor
Posts: 106

Re: log Error in format

Posted in reply to deleted_user
O.k., I guess I see. You have a mixture of input styles in your input statement.

The first part ("input projid") is referred to as "list input", a technique where you just name the variables without assigning an explicit informat.
The other part "input ... startdate date9. enddate date9." is referred to as "formatted input". As SAS processes the input statement it moves it's internal column pointer ahead. With formatted input the column pointer points to the column right after the (in)formatted value. In your case that means "enddate" begins with the blank separating your date values. This makes enddate having an invalid value.
Possible solutions:
a) manually move the column pointer by one column
[pre]
input projid startdate date9. +1 enddate date9. ;
[/pre]
b) search for and read the sections on the "colon modifier" in the input statement documentation
[pre]
input projid startdate : date9. enddate : date9. ;
[/pre]
Quote from 9.1.3 documentation: For a numeric variable, this format modifier reads the value from the next non-blank column until the pointer reaches the next blank column or the end of the data line, whichever comes first.
Ask a Question
Discussion stats
  • 3 replies
  • 125 views
  • 0 likes
  • 2 in conversation