Help using Base SAS procedures

Why do I need a colon modifier for dates?

Accepted Solution Solved
Reply
Contributor
Posts: 35
Accepted Solution

Why do I need a colon modifier for dates?

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;


Accepted Solutions
Solution
‎07-08-2015 10:26 AM
Super User
Posts: 10,046

Re: Why do I need a colon modifier for dates?

@@ 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.




                                                                                        

View solution in original post


All Replies
Super User
Posts: 11,343

Re: Why do I need a colon modifier for dates?

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.

Respected Advisor
Posts: 3,799

Re: Why do I need a colon modifier for dates?

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?

Super User
Posts: 10,046

Re: Why do I need a colon modifier for dates?

It is not formatted input ' s error .

The error is from @@ .

Code: Program

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;


Log: Program

Notes (2)

1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;

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

Valued Guide
Posts: 860

Re: Why do I need a colon modifier for dates?

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;

Contributor
Posts: 35

Re: Why do I need a colon modifier for dates?

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.

Solution
‎07-08-2015 10:26 AM
Super User
Posts: 10,046

Re: Why do I need a colon modifier for dates?

@@ 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.




                                                                                        

Contributor
Posts: 35

Re: Why do I need a colon modifier for dates?

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.

Super User
Posts: 10,046

Re: Why do I need a colon modifier for dates?

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 .

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 8 replies
  • 452 views
  • 1 like
  • 5 in conversation