BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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
3 REPLIES 3
GertNissen
Barite | Level 11
"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.
chaitanya
Calcite | Level 5

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;

data_null__
Jade | Level 19

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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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