Help using Base SAS procedures

Getting quoted string warning with a format definition

Accepted Solution Solved
Reply
Super Contributor
Posts: 400
Accepted Solution

Getting quoted string warning with a format definition

Hello, I have a process that creates proc format statements for my data.  For some of the formats I get this warning: "The quoted string currently being processed has become more than 262 characters long". I know I can use OPTIONS NOQUOTELENMAX to suppress this warning, but I want to know if there is any effect on the formats.  I have users who will be creating data sets and will be generating proc formats and I have to make sure it is all correct. Here is an example: data _null_; x='The is a "test".  Some of my strings have double quotes.The is a "test".  Some of my strings have double quotes.The is a "test".  Some of my strings have double quotes.The is a "test".  Some of my strings have double quotes.The is a "test".  Some of my strings have double quotes.'; run; The variable x is one continuous string within sas. Thank you


Accepted Solutions
Solution
‎09-19-2014 02:49 PM
Respected Advisor
Posts: 3,799

Re: Getting quoted string warning with a format definition

Posted in reply to jerry898969

I was suggesting to use QUOTE function, it figures out the embedded quote problem for you.

TextRows = quote(substrN(startpos,200));

Not sure is you need substrN or subPAD.

View solution in original post


All Replies
Respected Advisor
Posts: 3,799

Re: Getting quoted string warning with a format definition

Posted in reply to jerry898969

Use SYMGET

length X $256; or what you need;

x = symget('TEST');

Super User
Super User
Posts: 7,977

Re: Getting quoted string warning with a format definition

Posted in reply to jerry898969

How are you generating it?  Its likely the compiler is just complaining, for instance if you do:

data _null_;

     call execute('lksdhgdsghsodighoishgoihsipgpispghspdhgpsd

                              lksdhgdsghsodighoishgoihsipgpispghspdhgpsd

                              lksdhgdsghsodighoishgoihsipgpispghspdhgpsd

                              lksdhgdsghsodighoishgoihsipgpispghspdhgpsd

                              lksdhgdsghsodighoishgoihsipgpispghspdhgpsd

                              lksdhgdsghsodighoishgoihsipgpispghspdhgpsd');

...

Then it will run this complaint, although the output would work fine.

You could always break the generation up:

data _null_;

     call execute('lksdhgdsghsodighoishgoihsipgpispghspdhgpsd');

     call execute('lksdhgdsghsodighoishgoihsipgpispghspdhgpsd');

...

Or just use the options.

Super Contributor
Posts: 400

Re: Getting quoted string warning with a format definition

Thank you both for your quick reply. What my process is doing is it is pulling data from a formats table that lists the code value and text values for a variable that is selected by the user.  This will create a proc format statement like this

proc format ;

VALUE Testing

         1 = 'TEST 1'

         2 = 'TEST 2'        

         0 = 'The is a "test".  Some of my strings have double quotes.The is a "test".  Some of my strings have double quotes.The is a "test".  Some of my strings have double quotes.The is a "test".  Some of my strings have double quotes.The is a "test".  Some of my strings have double quotes.'   ;

run ;

It can be from 1 to over 1000 formats.  It's when I'm running this proc format that the warning appears.  How would I edit this proc format to correct it?

I can't split the lines since it would make some of the files very large.

Thank you again for your help

Super User
Super User
Posts: 7,977

Re: Getting quoted string warning with a format definition

Posted in reply to jerry898969

Could you pop options symbolgen mlogic mprint; on and post the log as I can't replicate.  The way tend to do these type of things is:

proc format cntlout=work.tmp;
  value testing
    1 = 'TEST1'
    2 = 'TEST2'
    0 = 'This is a "TEST"';
run;

data _null_;
  set work.tmp end=last;
  if _n_=1 then call execute('proc format; value testing ');
  call execute(' '||strip(start)||' = '||"'"||strip(label)||"'");
  if last then call execute(';run;');
run;

Respected Advisor
Posts: 3,799

Re: Getting quoted string warning with a format definition

Posted in reply to jerry898969

Instead of generating code for PROC FORMAT create a CNTLIN data set and run PROC FORMAT CNTLIN=CONTROL;

Super User
Posts: 19,833

Re: Getting quoted string warning with a format definition

Posted in reply to jerry898969

Consider using CNTLIN instead of generating the format statements to avoid the error entirely and because it makes more sense in general?

Super Contributor
Posts: 400

Re: Getting quoted string warning with a format definition

Hello,

My process generates sas files for my users based on the variables they select.  Based on those variables I pull the formats and create the file.

The user does not get the actual data i'm using for my formats they only see the format file.

I did find if I split the long sting at the 200 character mark and put the rest on the next row that it works.

proc format ;

value testing 0 = 'The is a "test".  Some of my strings have double quotes.The is a "test".  '

'Some of my strings have double quotes.The is a "test".  Some of my strings have '

'double quotes.The is a "test".  Some of my strings have double quotes.The is a "test".  '

'Some of my strings have double quotes.'  ;

run ;

My issue now is how can I automate this process to split the string based on a length?  I appreciate all your help.

Super User
Super User
Posts: 7,062

Re: Getting quoted string warning with a format definition

Posted in reply to jerry898969

If you want to test it run the generated code to create the format(s). 

Then use PROC FORMAT to generate a CNTLOUT dataset and compare the START and LABEL values to your source table.

Respected Advisor
Posts: 3,799

Re: Getting quoted string warning with a format definition

Posted in reply to jerry898969

You can automate the splitting of the string and use QUOTE function or $QUOTE format to quote the values when you generate the proc format statements.  This way you shouldn't need to worry about any embedded quotes in the source data.

Super Contributor
Posts: 400

Re: Getting quoted string warning with a format definition

Posted in reply to data_null__

Hello,

This is the code I'm currently using and it seems to work good.  I'm splitting strings longer then 200.

data TempText ;

length textLen cRows startPos 8. TextRows $250 ;

set Temp ;

textLen = length(testtext) ;

cRows = int(textLen / 200) + 1 ;

do i=1 to cRows ;

startPos = ((i - 1) * 200) + 1 ;

TextRows = "'" || tranwrd(trim(substr(testtext, startPos, 200)),"'","''") || "'"

; output ;

end ;

run ;

Do you see any future issues with this approach?

Thank you

Solution
‎09-19-2014 02:49 PM
Respected Advisor
Posts: 3,799

Re: Getting quoted string warning with a format definition

Posted in reply to jerry898969

I was suggesting to use QUOTE function, it figures out the embedded quote problem for you.

TextRows = quote(substrN(startpos,200));

Not sure is you need substrN or subPAD.

Super User
Super User
Posts: 7,062

Re: Getting quoted string warning with a format definition

Posted in reply to jerry898969

You could also just split the codes at the point where you are generating the PROC FORMAT code.

data example;

  length fmtname $32 value 8 original new $500;

  fmtname='testing';

  value=0;

  original= 'The quick brown fox jumped over the lazy dog. '

       || 'Now is the time for all good men to come to the aid of their party.'

  ;

run ;

%let max=50 ;

filename code temp;

data _null_;

  file code ;

  if _n_=1 then put 'proc format;';

  if eof then put 'run;' ;

  set example end=eof;

  by fmtname ;

  if first.fmtname then put 'value ' fmtname ;

  put  value 8. '=' @ ;

  do s=1 to length(original) by &max ;

new=quote(substr(original,s,min(&max,length(original)-s+1)));

    put @10 new ;

  end;

  if last.fmtname then put ';' ;

run;

%inc code /source2;

data _null_;

   x=0;

   format x testing.;

   put x= ;

run;


318 +proc format;

319 +value testing

320 +       0="The quick brown fox jumped over the lazy dog. Now "

321 +         "is the time for all good men to come to the aid of"

322 +         " their party."

323 +;

NOTE: Format TESTING has been output.

324 +run;


Super Contributor
Posts: 400

Re: Getting quoted string warning with a format definition

Thank you so much for your help.

I was able to get it working and I changed some of the code based on your suggestions.

Thank you

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 13 replies
  • 500 views
  • 3 likes
  • 5 in conversation