I am aware that you need a colon modifier for charcter variables with length longer than 8 characters and for reading in variables in non standard format i.e. with commas and decimal places but why do I need one for the program below to get it to work correctly?
data dateat;
input Date date7. HighTemp @@;
format date date9.;
datalines;
01APR90 68 02APR90 67 03APR90 70
04APR90 74 05APR90 72 06APR90 73
07APR90 71 08APR90 75 09APR90 76
;
run;
proc print data=dateat;
run;
@@ will hold the point all the time ,even it is another row.
For your scenario, CARDS default has 80 length .
When point reach at 01APR90 68 02APR90 67 03APR90 70 <--
There are still some blanks left . therefore when you run input Date date7. again ,
It is inputting a blank ,SAS throw a exception . Check the Log :
It is 04APR90 not 01APR90,When SAS meet an error.
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
53
54 data dateat;
55 input Date date7. HighTemp @@;
56 format date date9.;
57 datalines;
NOTE: Invalid data for HighTemp in line 59 1-7.
RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0
59 04APR90 74 05APR90 72 06APR90 73
Date=. HighTemp=. _ERROR_=1 _N_=4
NOTE: Invalid data for Date in line 59 9-15.
NOTE: Invalid data for HighTemp in line 59 16-18.
Try
data dateat;
informat date date7. ;
input Date HighTemp @@;
format date date9.;
datalines;
01APR90 68 02APR90 67 03APR90 70
04APR90 74 05APR90 72 06APR90 73
07APR90 71 08APR90 75 09APR90 76
;
run;
Formats when specified as part of an input statement get picky about exact lengths and the spaces between variables aren't counted quite as you expect.
ballardw wrote:
Formats when specified as part of an input statement get picky about exact lengths and the spaces between variables aren't counted quite as you expect.
What does that mean?
It is not formatted input ' s error .
The error is from @@ .
data dateat;
input Date date7. HighTemp @;output;
input Date date7. HighTemp @;output;
format date date9.;
datalines;
01APR90 68 02APR90 67 03APR90 70
04APR90 74 05APR90 72 06APR90 73
07APR90 71 08APR90 75 09APR90 76
;
run;
Notes (2)
53
54 data dateat;
55 input Date date7. HighTemp @;output;
56 input Date date7. HighTemp @;output;
57 format date date9.;
58 datalines;
NOTE: The data set WORK.DATEAT has 6 observations and 2 variables.
NOTE: DATA statement used (Total process time):
real time 0.05 seconds
cpu time 0.01 seconds
62 ;
63 run;
64
65 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
75
Xia Keshan
Separate the input and the informat lines. I tested it and do not know why the : modifier works, If anyone has any additional information on that I would be interested to know:
data dateat;
infile cards;
informat Date date7.;
format date date9.;
input date hightemp @@;
cards;
01APR90 68 02APR90 67 03APR90 70
04APR90 74 05APR90 72 06APR90 73
07APR90 71 08APR90 75 09APR90 76
;
run;
It works with the colon modifier...
input Date : date7. HighTemp @@;
My question was/ is why? I guess the date format is non standard format as well; same as numbers with commas and decimal places. Thanks.
@@ will hold the point all the time ,even it is another row.
For your scenario, CARDS default has 80 length .
When point reach at 01APR90 68 02APR90 67 03APR90 70 <--
There are still some blanks left . therefore when you run input Date date7. again ,
It is inputting a blank ,SAS throw a exception . Check the Log :
It is 04APR90 not 01APR90,When SAS meet an error.
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
53
54 data dateat;
55 input Date date7. HighTemp @@;
56 format date date9.;
57 datalines;
NOTE: Invalid data for HighTemp in line 59 1-7.
RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0
59 04APR90 74 05APR90 72 06APR90 73
Date=. HighTemp=. _ERROR_=1 _N_=4
NOTE: Invalid data for Date in line 59 9-15.
NOTE: Invalid data for HighTemp in line 59 16-18.
I think Xia got it, and he has the best/most comprehensive answer.
With Modified list/colon modifier -- it will not look further than the 3 record on the first line. Where as with an informat / formatted input it's looking for a date value again on the first line after the third one is read in. thanks all.
Modified list/colon modifier will jump these blanks and set point at the second row 04APR90 , while formatted input( without colon) still set point where it is ,and will input blanks , that is the reason why SAS will throw an exception .
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.