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

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

1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19

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

13 REPLIES 13
data_null__
Jade | Level 19

Use SYMGET

length X $256; or what you need;

x = symget('TEST');

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

jerry898969
Pyrite | Level 9

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

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;

data_null__
Jade | Level 19

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

Reeza
Super User

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

jerry898969
Pyrite | Level 9

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.

Tom
Super User Tom
Super User

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.

data_null__
Jade | Level 19

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.

jerry898969
Pyrite | Level 9

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

data_null__
Jade | Level 19

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.

Tom
Super User Tom
Super User

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;


jerry898969
Pyrite | Level 9

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 13 replies
  • 1659 views
  • 3 likes
  • 5 in conversation