BookmarkSubscribeRSS Feed
Pooja98
Fluorite | Level 6

Hi All,

 

I came across a new option in SAS input statement like

 

It's a part of code:

 

Input

MONTH_ID         : ?? BEST6.

SVC_DT           : ?? YYMMDD8.
PATIENT_ID       : ?? BEST11.;

 

The one on the left side is variable. What is the use of ":" and "??" in input statement?
Can anyone explain in brief?

 

Thanks In Advance

3 REPLIES 3
Kurt_Bremser
Super User

The colon modifier lets you use the informat while the INPUT statement still honors the delimiter. The ?? modifier prevents printing an ERROR message (and the contents of the input line) to the log if invalid data is encountered; it also prevents the setting of the automatic _ERROR_ variable (a single ? would not do that).

ballardw
Super User

And a why. This code may be used in the case of data that the programmer knows is sometimes invalid for the data type, such as NA for not applicable, and they don't want to see many messages related to invalid data that might occur when the invalid values are expected.

 

See the log when running these two examples:

data example1;
  infile datalines dlm=',';
  input x :date9. y :best5.;
datalines;
01Jan2022,123.4
 NA ,<missing>
;

data example2;
  infile datalines dlm=',';
  input x :??date9. y :??best5.;
datalines;
01Jan2022,123.4
NA,<missing>
;

For values that I know and expect, such as NA or <missing> I might prefer a custom informat to set a special missing value in the data so those can be recorded and leave the ?? for completely unexpected values.

Because of several data sources I deal with that can't be bothered to document anything or will change code values without notification I do not typically use the ?? because I have to go back and ask why not-acceptable values appear in the data and what they actually mean.

Tom
Super User Tom
Super User

The : means to use list mode even though you have included an in-line informat specification.

The ?? means to not generate error messages or set the _ERROR_ flag variable for values that the informat cannot handle.  

 

NOTE when using the : modifier the width on the informat specifications will be ignored by the INPUT statement. Instead it will read all of the text in the next word on the line. The only case where you would want to include the width is for reading character variables that you have not yet defined.  The input will still ignore the width, but the data step compiler will guess that you wanted to define the length of the variable to match the width on the informat specification instead of using the default length of $8.

 

NOTE that BEST is the name of a FORMAT.  If you use as the name of an INFORMAT then SAS will treat it as an alias for the normal numeric informat.  Since the default is to treat values as numeric there is no need to use the informat and so no need to include the : modifier either in the INPUT statement for those variables.

 

So cleaned up code would be:

input
  MONTH_ID   ??
  SVC_DT    :?? YYMMDD.
  PATIENT_ID ??
;

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 532 views
  • 0 likes
  • 4 in conversation