List all variables in SAS

Accepted Solution Solved
Reply
Regular Contributor
Posts: 150
Accepted Solution

List all variables in SAS

I am managing a large dataset (>2000 variables) and I am cleaning the data currently. We use program to collect the data and right now for the options don't know, refuse to answer, and skipped, the program outputs different numbers based on the questions. For example, don't know may equal, 97,997,9997,99997...I need to change them all to equal the same value, 9997. I know how to write that code using an array. What I want to know is if there is a way to get SAS to list all the numeric variables and character variables separately so I can easily copy and paste them into an array since the array requires that all variables be of the same type to work. I am trying to avoid going through the data dictionary and proc contents to hand type every variable as most of them include don't know, refure to answer, or skipped values. Any suggestions would be greatly appreciated.


Accepted Solutions
Solution
‎03-11-2013 07:46 PM
Super User
Super User
Posts: 7,076

Re: List all variables in SAS

Posted in reply to rfarmenta

I would recommend outputting the names to a text file or a spreadsheet so that it will be easier for you to copy and paste.

proc contents data=mydataset noprint out=contents ; run;

data _null_;

  set contents;

  file 'mydataset_vars.txt';

  put name;

run;

View solution in original post


All Replies
Super User
Posts: 19,868

Re: List all variables in SAS

Posted in reply to rfarmenta

What about _numeric_ and _character_ shortcuts?

Or you can query your data dictionary tables and store them in macro variables.

You could also consider applying two formats, one character and one numeric, to the data that do the recoding.

Super Contributor
Posts: 644

Re: List all variables in SAS

Just to expand on Reeza's suggestion:

array nums {*} _Numeric_ ;

array text {*} _Character_ ;

You might have to skip some columns if they are not relevant - eg ID

Richard

Solution
‎03-11-2013 07:46 PM
Super User
Super User
Posts: 7,076

Re: List all variables in SAS

Posted in reply to rfarmenta

I would recommend outputting the names to a text file or a spreadsheet so that it will be easier for you to copy and paste.

proc contents data=mydataset noprint out=contents ; run;

data _null_;

  set contents;

  file 'mydataset_vars.txt';

  put name;

run;

Regular Contributor
Posts: 150

Re: List all variables in SAS

Thank you all for your suggestions! I ended up doing what Tom recommended so I could copy and paste the variable names easily. Thank you!

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 317 views
  • 8 likes
  • 4 in conversation