BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Nyioves
Calcite | Level 5

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

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

8 REPLIES 8
ballardw
Super User

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.

data_null__
Jade | Level 19

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?

Ksharp
Super User

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

Steelers_In_DC
Barite | Level 11

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;

Nyioves
Calcite | Level 5

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.

Ksharp
Super User

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




                                                                                        

Nyioves
Calcite | Level 5

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.

Ksharp
Super User

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 .

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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