Buras
Buras

Reputation: 3099

Where to specify input @ in SAS?

In the following code

data temp2;
input id 1 @3 date mmddyy11.;
cards;
1 11/12/1980
2 10/20/1996
3 12/21/1999
;
run;

what do 1 @3 symbols mean ? i presume 1 means that id is the first character in the data . I know that @3 means that date variable starts with the third character , but why is it in front of date whereas 1 is after id?

Upvotes: 1

Views: 78

Answers (1)

Joe
Joe

Reputation: 63424

Because that's a badly written input statement. You can specify input in a number of ways, and that mixes a few different ways to do things which happen to be allowed to mix (mostly). Read the SAS documentation on input for more information.

Some common styles that you can use:

input @1 id $5.;  *Formatted input.  Allows specification of start position and informat, more useful if using date or other informat that is not just normal character/number.;
input id str $ otherstr $ date :date9.; *List input. This is for delimited text (like a CSV), still lets you specify informat.
input @'ID:' id $5.; *A special case of formatted input.  allows you to parse files that include the variable name, useful for old style files and some xml/json/etc. type files;
input x 1-10 y 11-20; *Column input. Not used very commonly as it's less flexible than start/informat style.;

There are other options (such as named input) that are not very frequently used in my experience.

In your specific example, the first variable is read in with column input [id 1 says 'read a 1 character numeric from position 1 into id'] and then the second variable is read with formatted input [@3 date mmddyy11. says 'Read an 11 character date variable from position 3[-13] into a numeric using the date informat to translate it to a number.'] It also says someone gave you that code who isn't very familiar with SAS, since mmddyy10. is the correct informat - the 11th character cannot be helpful.

Upvotes: 2

Related Questions