Help using Base SAS procedures

confused with use of colonmodifier with informats can anybody help?

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 7
Accepted Solution

confused with use of colonmodifier with informats can anybody help?

data samp ;

input id date :ddmmyy10. age$ 2.;

cards;

102 12/11/198312

103 12/11/198914

;

run;

whenever i place colon modifier before a informat, it is reading a column larger than specified width in character variables and more than that in numeric... .please clarify how sas intrepets colon modifier..


Accepted Solutions
Solution
‎04-02-2013 08:39 AM
Respected Advisor
Posts: 3,773

Re: confused with use of colonmodifier with informats can anybody help?

This is the same only different. Smiley Happy  SAS is ignoring the width specification on the numeric informat.  If you want to read the data properly use formatted input for both date and age.  Remove the colon.

29         data _null_;
30            infile cards column=col;
31            input id date :ddmmyy10. @;
32            put date=date. col=;
33            input age$ 2.;
34            put age= col=;
35            list;
36         cards;

NOTE:
Invalid data for date in line 37 5-16.
date=
. col=18
age=  col=
20
RULE:      ----+----
1----+----2----+----
37         102 12/11/198312
col=
20 id=102 date=. age=  _ERROR_=1 _N_=1
NOTE: Invalid data for date in line
38 5-16.
date=
. col=18
age=  col=
20
38         103 12/11/198914
col=
20 id=103 date=. age=  _ERROR_=1 _N_=2

View solution in original post


All Replies
Solution
‎04-02-2013 08:39 AM
Respected Advisor
Posts: 3,773

Re: confused with use of colonmodifier with informats can anybody help?

This is the same only different. Smiley Happy  SAS is ignoring the width specification on the numeric informat.  If you want to read the data properly use formatted input for both date and age.  Remove the colon.

29         data _null_;
30            infile cards column=col;
31            input id date :ddmmyy10. @;
32            put date=date. col=;
33            input age$ 2.;
34            put age= col=;
35            list;
36         cards;

NOTE:
Invalid data for date in line 37 5-16.
date=
. col=18
age=  col=
20
RULE:      ----+----
1----+----2----+----
37         102 12/11/198312
col=
20 id=102 date=. age=  _ERROR_=1 _N_=1
NOTE: Invalid data for date in line
38 5-16.
date=
. col=18
age=  col=
20
38         103 12/11/198914
col=
20 id=103 date=. age=  _ERROR_=1 _N_=2
Occasional Contributor
Posts: 7

Re: confused with use of colonmodifier with informats can anybody help?

Thanks for clarifying me....i have just one more doubt.....u said that first it reads the data till the delimiter then truncates it...will it read the data into PDV  and truncate afterwards? how the processing happens?

Respected Advisor
Posts: 3,773

Re: confused with use of colonmodifier with informats can anybody help?

In the other example there is truncation because $10 defines the length of the otherwise undeclared character variable.  The input statement with :$10. reads until the delimiter is found with is demonstrated by the COLUMN position.  Truncation occurs when the character string is stored or written to the PDV (I suppose is a good enough way to describe it).

☑ This topic is SOLVED.

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

Discussion stats
  • 3 replies
  • 137 views
  • 4 likes
  • 2 in conversation