Help using Base SAS procedures

Converting All variables to Character

Reply
Contributor
Posts: 59

Converting All variables to Character

Hi,

I have a dataset with around 600 attributes. Couple of them are numeric and others character. Is there a way I can convert all of them to character of length 20 in a single go?

Thanks
Super User
Posts: 5,257

Re: Converting All variables to Character

I suggest that you write a macro that reads out all numeric variables in the table, create assignment statements using the put function, and drops the original numeric variables.
/Linus
Data never sleeps
Frequent Contributor
Frequent Contributor
Posts: 76

Re: Converting All variables to Character

There is a macro on tech support web site that does this...


http://support.sas.com/kb/22/218.html
Super Contributor
Super Contributor
Posts: 3,174

Re: Converting All variables to Character

Do you presume that these SAS NUMERIC variables are decimal (using a SAS-default output FORMAT)? And where there is a specific output FORMAT, you would likely want to use that format in any "generated" code used with SAS DATA step assignment statements, as mentioned by Linus H. And, so, would the output be left-justified or right-justified in the SAS CHARACTER, length $20, converted variable values?

So, you could make use of the SAS-maintained views SASHELP.VCOLUMN to interrogate your tables, which could be used to generate SAS DATA step code for assigning the CHARACTER variables. After using SAS code to generate the SAS code out to a TEMP external (sequential) file, you would %INCLUDE that code to create the new SAS variables (possibly, hopefully in a different SAS table).

Of course, questions to ask: why do you want to do this? what is your quest?

Scott Barry
SBBWorks, Inc.
Ask a Question
Discussion stats
  • 3 replies
  • 3106 views
  • 0 likes
  • 4 in conversation