BookmarkSubscribeRSS Feed
Ronein
Onyx | Level 15

Hello friends

May I ask please what is the target of @ symbol in this example.

I also want to ask what is the meaning of @6   @13   @22?

Why the person who created this program used these numbers 6 13 22?

 

DATA raw4;
INPUT @6 date1 mmddyy6. @13 date2 mmddyy8. @22 date3 mmddyy10.;
FORMAT date1 ddmmyy10. date2 ddmmyyb10. date3 ddmmyyc10.;
CARDS;
042708 04-27-08 04 27 2008
;
RUN;

10 REPLIES 10
RW9
Diamond | Level 26 RW9
Diamond | Level 26

@ means move the pointer to position.  So:

INPUT @6 date1 mmddyy6. 

Means move the read position to character 6, then read 6 (from the length in mmddyy) characters from there:
042708 04-27-08 04 27 2008

           ^             ^

          from        to

 

Its just moving the pointer forward on the read line to get data from exact positions.  

singhsahab
Lapis Lazuli | Level 10

Dear 

 

- in formatted input style it says from which location variable value need to read or move the pointer to that position and start reading observation from that index position. 

 

 

@6  -  will start reading at the position 6  

@13 - will start reading at the position 13

 @22 - will start reading at the position 22

 

Ronein
Onyx | Level 15

date1 var has 6 digits

date2 var has 8 digits

date3 var has 10 digits

between date1  and date2 there is 1 digit space

between date2  and date3 there is 1 digit space

I don't understand why they use @6  @13  @22????

 

 

Kurt_Bremser
Super User

@Ronein wrote:

 

@I don't understand why they use @6  @13  @22????

 


to make life interesting for you?

Frankly, you need to ask the person who wrote that.

It's clearly not working, you'd be better off without pointers, but with partial use of colon modifiers:

data raw4;
input date1 :mmddyy6. date2 :mmddyy8. date3 mmddyy10.;
format date1 ddmmyy10. date2 ddmmyyb10. date3 ddmmyyc10.;
cards;
042708 04-27-08 04 27 2008
;
run;
Ronein
Onyx | Level 15

Thank you very much.

I understood that the person who wrote this program out the pointers in the wrong position.

I fixed it and it is working great .

I just want to ask you pleas about use colon modifiers.

What is it doing exactly?

DATA raw4;
INPUT @1 date1 mmddyy6. @8 date2 mmddyy8. @17 date3 mmddyy10.;
FORMAT date1 date9. date2 date9. date3 date9.;
CARDS;
042718 04-27-18 04 27 2018
;
RUN;

/*Other way*/
data raw4;
input date1 :mmddyy6. date2 :mmddyy8. date3 mmddyy10.;
format date1 date9. date2 date9. date3 date9.;
cards;
042718 04-27-18 04 27 2018
;
run;
/*Here we use colon modifiers: instead of pointers*/
Ronein
Onyx | Level 15

The colon (:) modifier allows you to read nonstandard data values and character values that are longer than eight characters, but which have no embedded blanks.

Is it the case here?

Do we have nonstandard data in this example?

 

Astounding
PROC Star

Your data is all standard data.  The typical non-standard data does not line up from row to row.  For example, a date begins at column 6 on row 1, but begins at column 8 on row 2.  When your fields are in the same position for every line, you would not need a colon.

 

Related points to consider:  would your program still work if there are missing values within your data?  Would it still work if a character value contains an embedded blank (such as trying to read a CITY value of "New York")?

 

Your final program and your data don't have any of these problems.

 

Kurt_Bremser
Super User

I you use a format on its own (no positions, no colon), the defined length of the format will determine the number of characters read. With the colon, the delimiters will determine the number of characters read, and the resulting string after that is fed through the format.

So as long as the delimiters can be used (in your example, the first two columns), use the colon; in order to (forcibly) read the next 8 characters (after the second delimiter), no colon modifier is used, so the blanks within those 8 characters are not used as delimiters.

Tom
Super User Tom
Super User

There are two basic input modes you can use with the INPUT function.  In LIST mode SAS will recognize the delimiters between the tokens (words) in the line.  In formatted mode SAS will read exactly the number of characters that the informat specification indicates.

 

The colon modifier allows you to include an informat specification in your INPUT statement and still have SAS use LIST mode in parsing the line (moving the column pointer).

 

For your data the complexity is that the third field has embedded delimiters.  So you are reading the first two fields using list mode, but switching to formatted input for the last field.  You might also try using the & modifier for the third field.  That modifier tells SAS to accept single delimiters as part of the current token (word) and look for two or more delimiters to end the token.

 

Also another way to tell SAS what informat to use is to attach an INFORMAT to the variable. 

 

Also note that when reading with list mode SAS will ignore the width on the informat specification. Instead it will use the width of the actual token in the data that is being read.

 

data raw4;
  input date1 date2 date3 & ;
  informat date1-date3 mmddyy. ;
  format date1-date3 date9.;
cards;
042718 04-27-18 04 27 2018
;

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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
  • 10 replies
  • 2046 views
  • 2 likes
  • 6 in conversation