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

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

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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

 

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

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

 

GustavSandberg
Calcite | Level 5

Thank you!

 

I had tried option number 1 with no success. Had never seen option number 2 before, and that worked!

 

 

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
  • 2 replies
  • 3823 views
  • 0 likes
  • 2 in conversation