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.
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;
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.
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
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;
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!
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.
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.