Help using Base SAS procedures

Column Pointer Controls - @ cont...

Reply
N/A
Posts: 0

Column Pointer Controls - @ cont...

Cont... from previous post -
The symbol combination for less than or equal to was not allowed here in the post. The post got ended there. Hence using the words -

1 (less than or equal to) N (less than or equal to) 2147483647.
301 run;

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set SAS_EX.GC_PEOPLE may be incomplete. When this step was stopped there were 0
observations and 1 variables.
WARNING: Data set SAS_EX.GC_PEOPLE was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
real time 0.05 seconds
cpu time 0.01 seconds


Observation 03:
input @1.35 Name $;
run;

Log:
307 input @1.35 Name $;
----
22
500
ERROR 22-322: Expecting a name.

ERROR 500-185: Decimal specified for informat F is invalid.

308 run;

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set SAS_EX.GC_PEOPLE may be incomplete. When this step was stopped there were 0
observations and 0 variables.
WARNING: Data set SAS_EX.GC_PEOPLE was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
real time 0.05 seconds
cpu time 0.01 seconds

It would be great if someone could let me know whether the documentation is incorrect?
SAS Super FREQ
Posts: 8,744

Re: Column Pointer Controls - @ cont...

Hi:
An INPUT statement or column pointer of -23 or 1.35 doesn't make sense to me, just for the sake of using a negative number or a decimal number to see what will happen.

In the past, if I have ever needed to use a negative number for column pointer control (mostly this has happened when using a PUT statement -- not an INPUT statement), I have used a variable to hold the negative number and then used the variable in the PUT statement.

This usage worked for me in an INPUT statement, but again I think it's an artificial example. For this data, the NAME starts at column 1, the AGE starts at column 10 and the OTHER variable starts at column 14, as shown in the DATALINES section below:
[pre]
datalines;
Alan 16 2
Bob 17 3
Carla 16 1
Dana 15 3
;
[/pre]

Then, you can see from the LOG that there are no errors for using variables with negative number:
[pre]
479 data tryread;
480 length name $8;
481 infile datalines;
482 negcol = -23;
483 colpnt = 10.35;
484 input @negcol name $8. @colpnt age 2. @14 other 1.;
485 return;
486 datalines;

NOTE: The data set WORK.TRYREAD has 4 observations and 5 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds

491 ;
492 run;
[/pre]

And, a PROC PRINT of the SAS data set shows that the input datalines were read correctly:
[pre]
Obs name negcol colpnt age other
1 Alan -23 10.35 16 2
2 Bob -23 10.35 17 3
3 Carla -23 10.35 16 1
4 Dana -23 10.35 15 3
[/pre]

But, as I said, I'm not sure about WHY you would want to do this. You quoted the documentation about @n -- Did you look at the example provided for that particular documentation section??

Featured in: Moving the Pointer Backward

and if you go to Example 7 on Moving the Pointer Backward, you will see the following example of using a negative number:

Example 7: Moving the Pointer Backward


This example shows several ways to move the pointer backward.

• This INPUT statement uses the @ pointer control to read a value for BOOK starting at column 26. Then the pointer moves back to column 1 on the same line to read a value for COMPANY:

input @26 book $ @1 company;

• These INPUT statements use +numeric-variable or +(expression) to move the pointer backward one column. These two sets of statements are equivalent.

• m=-1;
input x 1-10 +m y 2.;

• input x 1-10 +(-1) y 2.;


It seems to me that the example of using a negative number in parentheses or using a variable name (also shown in the doc) are pretty straightforward.

I guess for me, the bottom line is -- what does your data actually look like??? Do you really need to provide a negative number or a decimal number for an INPUT pointer control??? For what purpose?? Where you are reading data, there is no decimal location -- there are only whole columns. If you have binary or packed data, there are other ways to read the input file that are more accurate methods than using a negative number or a decimal number.

For future reference, it is possible to post material with < or > symbols. All you have to do is "mask" them so they are not interpreted as HTML tags by the forum posting mechanism, as described in this previous forum posting:
http://support.sas.com/forums/thread.jspa?messageID=27609毙
..which talks about characters like < or > and how to alter your posting so that these characters do not interfere with the posted information.

cynthia
N/A
Posts: 0

Re: Column Pointer Controls - @ cont...

Thanks a lot Cynthia for the Crystal clear explanation...

I am one week old into SAS and was trying to explore scenarios for what I read in the documentation. In the real world, this might not be a possibility.

Thanks so much and would come up with a better doubt next time.
SAS Super FREQ
Posts: 8,744

Re: Column Pointer Controls - @ cont...

Hi:
Since most of my explanation came -directly and unedited- from the documentation, my recommendation would be that you read or try the posted examples in the documentation as a means of understanding how various syntax alternatives work.

Also, having "real" scenarios or "real" data might be a better learning technique to find more common usage examples -- instead of focussing on some of the least common (but possible) usages. One way to find real scenarios aside from the documentation examples is to search for user group papers on your topic of interest. For example, a Google search on the string:
SAS DATA step INPUT statement

...yields as the first 2 hits some user group papers and a SAS paper that is a walkthrough of the DATA step and how it reads data. Even a simple search string:
SAS reading data

...nets quite a list of resources on the topic of using SAS to read data.

cynthia
Ask a Question
Discussion stats
  • 3 replies
  • 640 views
  • 0 likes
  • 2 in conversation