Help using Base SAS procedures

_n_ & _error_ in vector table

Reply
Super Contributor
Posts: 266

_n_ & _error_ in vector table

which 2 variable creates by _n_ & _error_ in vector table...can any1 guide me on this..

Super Contributor
Posts: 543

Re: _n_ & _error_ in vector table

Hi
from SAS page:
SAS(R) 9.2 Language Reference: Concepts, Second Edition
_N_  is initially set to 1. Each time the DATA step loops past the DATA statement, the variable _N_ increments by 1. The value of _N_ represents the number of times the DATA step has iterated.
_ERROR_  is 0 by default but is set to 1 whenever an error is encountered, such as an input data error, a conversion error, or a math error, as in division by 0 or a floating point overflow. You can use the value of this variable to help locate errors in data records and to print an error message to the SAS log.
Does this help?
Anca
Super Contributor
Posts: 266

Re: _n_ & _error_ in vector table

Posted in reply to AncaTilea

actualy i m looking for that when _n_ initialize then which 2 variable it creates in vector table...

Super Contributor
Posts: 543

Re: _n_ & _error_ in vector table

So, _N_ and _ERROR_ are automatically created but not 'kept" in the data step;

I don't think there are any 2 other variables created once _N_ initializes.

_N_ and _ERROR_ are the two variables created.

OK, I am talking in circles.

This reading should be helpful:

Step-by-Step Programming with Base SAS(R) Software

Smiley Happy

Super Contributor
Posts: 266

Re: _n_ & _error_ in vector table

Posted in reply to AncaTilea

i m sorry i thnk i m nt able to explain my query well.

i thnk i sud ask how _n_ and _error works in vector table.

i m going through with ur given doc. thanks

Super Contributor
Posts: 266

Re: _n_ & _error_ in vector table

Posted in reply to AncaTilea

_n_ and _error_ each creates 2 valriable in programme data vector... what is the name of that 2 variable n type of them ,

thanks in advance

SAS Super FREQ
Posts: 8,868

Re: _n_ & _error_ in vector table

Hi:

  Somehow I think there is confusion about what the question is. At first you posted "When _n_ initializes, then which 2 variables it creates in the vector table."

  Let me ease into this, first, by stating the fact that  _N_ does NOT initialize anything.And, second, the Program Data Vector (PDV) is a memory area. It is NOT a "vector table". At an iteration of a DATA step program, the Program Data Vector holds one observation at a time. So, the correct term for this memory area is PDV or Program Data Vector, not "vector table".

  I don't know how you got your question or who is asking the question or perhaps you got a bad translation of a question. In my reading of the postings in this thread, I think that your question might be better asked as something like this:

When a SAS DATA Step program creates the Program Data Vector (PDV), what 2 automatic variables are created?

and/or

In the Program Data Vector, what are the names and types of the 2 automatic variables that are created?

_N_ and _ERROR_ are the only 2 automatic variables created in the Program Data Vector (PDV). And, these 2 variables are only created when you use a DATA Step program. There is no Program Data Vector (PDV) created for SAS procedure steps.

In your last posting, you said that "_n_ and _error_ each creates 2 valriable in programme data vector... what is the name of that 2 variable n type of them" -- but from the very beginning, what you wrote was incorrect, so there is no way to answer the question that you asked.

_N_ and _ERROR_ do NOT create 2 variables each in the Program Data Vector. _N_ and _ERROR_ ARE the 2 variables created in the PDV.

When you write a DATA Step program, _N_ and _ERROR_ are created automatically in the Program Data Vector (PDV). These 2 automatic variables are both numeric variables. The values of these two variables will differ, because they each serve a different function. The documentation (from the site above), states EXACTLY what these 2 variables represent. The doc says that:

"The program data vector also contains two automatic variables, _N_ and _ERROR_. The _N_ variable counts the number of times the DATA step begins to iterate. The _ERROR_ variable signals the occurrence of an error caused by the data during execution. These automatic variables are not written to the output data set."

  There is no ambiguity in the documentation. _N_ does not do the initializing and there are ONLY 2 automatic variables created in the PDV when you execute a DATA step program. The area of memory in which these automatic variables exist is called the Program Data Vector (PDV). The only thing that is not explicitly stated (but is implied) in that paragraph is that _N_ is numeric (because it is a counter variable) and _ERROR_ is also numeric in type.

  There are other automatic variables that CAN be created in the PDV when you use syntax elements like BY or END= or IN=, however, you have to DO something to make the other automatic variables get created. Only _N_ and _ERROR_ are the variables that will be in the PDV just because you have written and executed a DATA Step program.

  I hope this clarifies the answer to the question(s) that you did not ask.

cynthia

Valued Guide
Posts: 2,177

Re: _n_ & _error_ in vector table

Posted in reply to Cynthia_sas

perhaps since vector is repeated so often by aman4sas, we should re-direct his query into the PROC IML group?

SAS Super FREQ
Posts: 8,868

Re: _n_ & _error_ in vector table

Good point, Peter! I had not considered whether PROC IML might have _N_ and _ERROR_. I still question whether variables would ever initialize anything. Usually variables are being initialized.

However, the IML forum is here: https://communities.sas.com/community/support-communities/sas_iml_and_sas_iml_studio

cynthia

Ask a Question
Discussion stats
  • 8 replies
  • 412 views
  • 1 like
  • 4 in conversation