This post was kindly contributed by NOTE: The blog of RTSL.eu - Development with SAS® - go there to comment and to read the full post. |
We all try to write data-driven code, or code that provides some degree of flexibility regarding its input data. We see these approaches as reducing maintenance and making the code more robust. There are a number of features in the SAS language that allow us to know more about the data that we’re using. Have you come across the DATA step’s CALL VNEXT routine? No? Then read on…
The CALL VNEXT routine returns the name, type and length of a variable in use in a DATA step. In this case, “in use” means “in the Program Data Vector (PDV)”. The PDV is the area of memory that the DATA step sets aside to hold all variables that are read in or created during execution of the DATA step. Understanding the PDV, how it is constructed, and how it is populated is very important if you are to truly master DATA step programming. CALL VNEXT provides a good insight.
The following log output shows how successive calls to VNEXT reveal details about each successive variable in the PDV. See how VNEXT returns information about first. and last. variables if a BY statement is present, plus _ERROR_ and _N_.
Ian Whitlock’s SAS User Group International (SUGI) paper titled “How to Think Through the SAS DATA Step” for SUGI 31 provides a lengthy and detailed exposé of the PDV and other key elements of DATA step programming. Jim Johnson’s “The Use and Abuse of the Program Data Vector” from this year’s SAS Global Forum (SGF) focuses neatly on the PDV. If you want to know more about the PDV, these papers are excellent sources of information.
Making your programs robust (meaning they don’t fail, for example, every time there’s the slightest mistaken variation in input data) and making them future-proof (meaning they don’t need to be amended and re-tested when, for example, field lengths get longer due to a corporate merger and the introduction of unforeseen data sources) won’t keep you busy with maintenance work but will give you time to spend on more productive, innovative activities. CALL VNEXT might just help you in achieving this goal.
This post was kindly contributed by NOTE: The blog of RTSL.eu - Development with SAS® - go there to comment and to read the full post. |