Help using Base SAS procedures

Colon Modifier

Reply
N/A
Posts: 0

Colon Modifier

Hi,
I am working on informats this week.
Can any body help me in understanding the colon modifier.I am not getting how it works in the input statement.
For example: as code shown below:-

DATA COLONS;
INPUT ID LASTNAME : $20. DOB : MMDDYY8.
HEIGHT WEIGHT GENDER :$1. AGE;
FORMAT DOB MMDDYY8.;
DATALINES;
1 SMITH 1/23/66 68 144 M 26
2 JONES 3/14/60 78 202 M 32
3 DOE 11/26/47 62 99 F 45
4 WASHINGTON 8/1/70 66 101 F 22
;
PROC PRINT DATA = COLONS;
TITLE 'Using colon modifier';
RUN;

I basically want to know when (for what kind of raw data) do we use the colon modifier????

Thanks,
SAS_Learner
SAS Employee
Posts: 174

Re: Colon Modifier

Posted in reply to deleted_user
"reads the value from the next non-blank column until the pointer reaches the next blank column, the defined length of the variable, or the end of the data line, whichever comes first."

Try some sample input with text containing spaces and/or no-column text and using/not using a lenght statement for your char var, then I'm sure you will see the result.

More info at http://support.sas.com/onlinedoc/913/getDoc/da/lrdict.hlp/a000144370.htm#a000853963 including 2 examples.
Occasional Contributor
Posts: 7

Re: Colon Modifier

Posted in reply to GertNissen

whatever u have said holds true for character variable, but for the numeric it is not following the same pattern, could you make it clear what happens in case of numeric variables?

why this program fails?

data samp ;

input id date $:10. age 2.;

cards;

102 12/11/198312

103 12/11/198914

;

run;

Respected Advisor
Posts: 3,799

Re: Colon Modifier

Posted in reply to chaitanya

When you use the colon SAS uses LIST input which scans the record until the delimeter is found.  The blank in this case.  So even though you specify $10. the input still scans until the delimiter is found in column 17 and the pointer is position at col=18 for the next read.  You have age 2. (formatted input) now but you are passed the spot where you need to be. Also $10. defines the length of date which truncates the 2 extra characters in the blank delimited field.

17         data _null_;
18            infile cards column=col;
19            input id date $:10. @;
20            put date= col=;
21            input age 2.;
22            put age= col=;
23            list;
24         cards;

date=
12/11/1983 col=18
age=
. col=20
RULE:      ----+----
1----+----2----+----
25         102 12/11/198312
date=
12/11/1989 col=18
age=
. col=20
26         103 12/11/198914
Ask a Question
Discussion stats
  • 3 replies
  • 261 views
  • 2 likes
  • 4 in conversation