BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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
3 REPLIES 3
Robert_Bardos
Fluorite | Level 6
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).
deleted_user
Not applicable
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):(Column).
4 at 233:17

Best Regards,
kriti
Robert_Bardos
Fluorite | Level 6
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.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 954 views
  • 0 likes
  • 2 in conversation