BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
rfarmenta
Obsidian | Level 7

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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

4 REPLIES 4
Reeza
Super User

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.

RichardinOz
Quartz | Level 8

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

Tom
Super User Tom
Super User

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;

rfarmenta
Obsidian | Level 7

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!

sas-innovate-2024.png

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.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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