- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Is there an easy way to extract the names of all the (user generated) variables being used in a SAS code? I have a large number of SAS programs and need to know which variables are being used to run those programs. I am trying to not do this manually.
Thank you to all who respond.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You can write a query to obtain a list of all variables that appear in all available data sets from SASHELP.VCOLUMN (or in SQL you can call it DICTIONARY.COLUMNS). You might want to limit the query to just certain data sets. Any "temporary" variable ... by that I mean variables used in the data step, but not saved to the output data set, would not be extracted by this query. Example:
proc sql;
create table list of variables as select
memname
,name
from sashelp.vcolumn where libname="WORK";
quit;
This only works for variables in data sets that are available in SAS. Your larger question, where you have lots of programs, is not directly answered by this method, as this method doesn't examine your code at all. Unless someone has already written code to examine your code and determine what variable names are used, I think it will be a rather Herculean task to create logic smart enough to extract variable names from SAS code. Which brings me to a curiosity question: why do you need this?
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Paige,
Thank you for your response. The SAS programs I have would extract some variables from some data tables (and also create some calculated variable).
At this time, those data tables are being created, and not ready for use. I am trying to determine whether all the variable I need to run those SAS programs are included the data tables that are being created.
Essentially trying to do a match between what I need and what I have without running the code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
If you don't want to run the code then your only option is to read and parse your SAS code looking for variable names. This is not easy or foolproof. For example If you use macro language at all then it becomes impossible to find generated variable names.
Producing a SAS log and parsing that is a better option and there is a SAS procedure for analysing executed code - PROC SCAPROC - at least with this you have a possibility of identifying generated variable names.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Makes sense.
I am not using a lot of macros in my code, but I will check out PROC SCAPROC. I wasn't familiar with it.