Help using Base SAS procedures

adding character to beginning/end of character variable values

Reply
New Contributor KDA
New Contributor
Posts: 4

adding character to beginning/end of character variable values

I've got a ~15000 obs x 2000 variable dataset (all variables are character). I'd like to add single quotation marks to the beginning and end of each variable value for all of the variables.
Is this possible?
SAS Super FREQ
Posts: 8,866

Re: adding character to beginning/end of character variable values

Hi:
I find myself wondering why you need to quote all your variable values. Are you by any chance, opening or exporting the file to Excel and find that your character variables are being treated as numbers by Excel, even though they are character variables in SAS? This is frequently one reason why people want to put quotes at the beginning of the variable value or around the variable value.

If this is the case, I recommend against the quoting the data method. When you're typing in Excel, Excel will "disappear" the quote. But, when the quote is part of the variable value, in some versions of Excel, you will still see the quote in the Excel data cell.

If this is not your reason for putting the quotes into the variable values, then you could, of course, use a DATA step program and an ARRAY for all your character variables and simply concatenate a single quote to the front of the variable value (and remember to adjust the length of the variable, if you need to) and then concatenate a quote to the end of the variable value. You'll also have to decide whether you want to preserve leading and trailing blanks in the variable value or not, because this will determine the kind of concatenate syntax you use.

If you ARE wanting your variable values to be treated as character values in Excel, there are other ways to accomplish this task. It depends on what method you're using to get your data into Excel. You may have to switch over to using ODS HTML-based methods or ODS TAGSETS.EXCELXP methods in order to pass a Microsoft character format to the Excel spreadsheet, but it is very possible to do this. Several examples have been posted to the forum of how to make sure that character variables stay character when the data is viewed in Excel. Here is just one of them:
http://support.sas.com/forums/thread.jspa?messageID=6820᪤

Your best bet for specific help might be to contact Tech Support so they can determine the best method for your situation.

cynthia
N/A
Posts: 0

Re: adding character to beginning/end of character variable values

if you really need this, don't do it to the data ~ just do it when you want to "see" it.
Where-ever that is, use a statement like[pre] format _character_ $quote1000. ;[/pre]
Then your data will "appear" quoted.
If you need to make this a permanent or default style for that dataset, use proc datasets. See the example: Modifying SAS Datasets at http://support.sas.com/documentation/cdl/en/proc/59565/HTML/default/a002473455.htm.

PeterC
Ask a Question
Discussion stats
  • 2 replies
  • 158 views
  • 0 likes
  • 3 in conversation