SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
chatur
Calcite | Level 5

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.

4 REPLIES 4
PaigeMiller
Diamond | Level 26

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
chatur
Calcite | Level 5

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.

SASKiwi
PROC Star

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.  

chatur
Calcite | Level 5
Thank you for your response.
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.

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 2495 views
  • 2 likes
  • 3 in conversation