BookmarkSubscribeRSS Feed
Aman4SAS
Obsidian | Level 7

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

8 REPLIES 8
AncaTilea
Pyrite | Level 9
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
Aman4SAS
Obsidian | Level 7

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

AncaTilea
Pyrite | Level 9

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

Aman4SAS
Obsidian | Level 7

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

Aman4SAS
Obsidian | Level 7

_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

Cynthia_sas
SAS Super FREQ

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

Peter_C
Rhodochrosite | Level 12

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

Cynthia_sas
SAS Super FREQ

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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 8 replies
  • 4485 views
  • 1 like
  • 4 in conversation