Hi all,
I have through a series of macros imported data from forms sent to me in Excel, where I have each answer in their own separate table named "DDDXXX" (as in DDD004, DDD342 etc.). Some of the questions have lengthy answers, and in their separate tables, the answers are still in their original length.
Almost all variables have a name with a space between two words, and some also have an apostrophe.
When I try to sum these tables into one, SAS seem to guess what the length of each variable should be, and will change the length. This results in a lot of answers being cut short.
For the Variable names with a space bar I have managed to work out to use the following input to keep the full length of the answers:
options validvarname=any;
data NAME_OF_NEW_TABLE ;
length 'Question-ID'n $35. 'Action done'n $40. 'Explain action'n $400.;
set DDD:;
format 'Question-ID'n $35. 'Action done'n $40. 'Explain action'n $400.;
keep 'Question-ID'n 'Action done'n 'Explain action'n;
run;
However, when I have a variable with a apostrophe in the name, I have not managed to figure out how to work around it. Since 'Action's result'n will not read the full variable name, because of the extra apostrophe.
If I first compile one table with all separate tables, and rename the varibles, and then try and change the length of the variable, the answers seem to have been cut short in the first step. Changing the length again does not bring the rest of the answer back.
If it possible to use my above code to get the same effect, but for a variable with an apostrophe?
Best regards,
Gustav
Just follow normal quoting rules for how to handle quoted strings that include the quote character.
1) Use different quoting character on the outside if possible.
2) Double any quote characters in the string.
"Action's result"n
'Action''s result'n
Just follow normal quoting rules for how to handle quoted strings that include the quote character.
1) Use different quoting character on the outside if possible.
2) Double any quote characters in the string.
"Action's result"n
'Action''s result'n
Thank you!
I had tried option number 1 with no success. Had never seen option number 2 before, and that worked!
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.