<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: quoting issues in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/quoting-issues/m-p/581241#M165177</link>
    <description>&lt;P&gt;You haven't really explained what your code is trying to do or even what problem you are having with it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But in general I find it much easier to use a data step to generate code into a file.&amp;nbsp; You can then examine the file and check its contents until you get the code generation logic right. (Or just generate it to the LOG) Once you know it works just %INCLUDE the file.&amp;nbsp; In addition you get to take advantage of all of the nice features of the DATA step and the PUT statement and FORMATs to make the code generation easier.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename code temp;

data _null_;
  set test2;
  file code;
  length filename $200 ;
  filename = cats('L:\B2C_PORTFOLIO2SCORE_results_ext_aug19_',obs,'.csv');
  put 'filename output ' filename :$quote. ' encoding="utf-8" ;'
    /  'PROC EXPORT data=crm_scored_hq(firstobs=' FI 'OBS=' LA ')'
       ' outfile=output dbms=csv replace'
    / ';'
    /  '  delimiter=";";'
    /  'run;'
  ;
run;

%include code / source2;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note you can use the FILENAME= option on the FILE statement to generate all of the delimited files in one pass of a single data step without all of the other rigmarole.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 14 Aug 2019 19:20:58 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2019-08-14T19:20:58Z</dc:date>
    <item>
      <title>quoting issues</title>
      <link>https://communities.sas.com/t5/SAS-Programming/quoting-issues/m-p/581216#M165164</link>
      <description>&lt;P&gt;It works but it feels complicated with the ''' workaround.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How Do I use the quoting functions wisely in this case?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instead of changing the firstobs= and obs= and filename manually, I use the construct proc sql + cats + select&amp;nbsp; into to execute the dynamic code.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With the last proc sql it works but I'd like to make it smarter and I have never really understood the %quote and %bquote and alike.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I feel that they could come at my rescue here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks, Arne&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename output "L:\B2C_PORTFOLIO2SCORE_results_ext_aug19_7.csv" encoding="utf-8";

PROC EXPORT data=crm_scored_hq(firstobs=1200001 obs=1400000) 
outfile=output dbms=csv replace;
delimiter=';';
run;


data test;

do fi=1 to 1379961 by 200000;
la=fi-1;
output;
end;

run;

data test2;
merge test(keep=fi) test(keep=la firstobs=2) end=eof;
if eof then la=fi+200000;
OBS=_N_;
run;

PROC SQL; select catt("filename output " || 
'''L:\B2C_PORTFOLIO2SCORE_results_ext_aug19_' ||
STRIP(PUT(OBS,3.)) ||".csv' encoding="||'''utf-8'''||";
PROC EXPORT data=crm_scored_hq(firstobs="|| STRIP(PUT(FI,8.)) || "OBS=" ||STRIP(PUT(LA,8.)) ||") 
outfile=output dbms=csv replace;
delimiter=';';
run;")
into :List separated by " "
from WORK.test2
;
quit;
 
&amp;amp;List.;* execute statements in mvar List;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Aug 2019 17:01:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/quoting-issues/m-p/581216#M165164</guid>
      <dc:creator>acordes</dc:creator>
      <dc:date>2019-08-14T17:01:27Z</dc:date>
    </item>
    <item>
      <title>Re: quoting issues</title>
      <link>https://communities.sas.com/t5/SAS-Programming/quoting-issues/m-p/581219#M165165</link>
      <description>&lt;P&gt;I'm not seeing how %QUOTE or %BQUOTE would help here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perhaps the non-macro QUOTE function might be helpful here, but it doesn't look like it would save a lot of programming.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Aug 2019 17:17:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/quoting-issues/m-p/581219#M165165</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-08-14T17:17:40Z</dc:date>
    </item>
    <item>
      <title>Re: quoting issues</title>
      <link>https://communities.sas.com/t5/SAS-Programming/quoting-issues/m-p/581241#M165177</link>
      <description>&lt;P&gt;You haven't really explained what your code is trying to do or even what problem you are having with it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But in general I find it much easier to use a data step to generate code into a file.&amp;nbsp; You can then examine the file and check its contents until you get the code generation logic right. (Or just generate it to the LOG) Once you know it works just %INCLUDE the file.&amp;nbsp; In addition you get to take advantage of all of the nice features of the DATA step and the PUT statement and FORMATs to make the code generation easier.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename code temp;

data _null_;
  set test2;
  file code;
  length filename $200 ;
  filename = cats('L:\B2C_PORTFOLIO2SCORE_results_ext_aug19_',obs,'.csv');
  put 'filename output ' filename :$quote. ' encoding="utf-8" ;'
    /  'PROC EXPORT data=crm_scored_hq(firstobs=' FI 'OBS=' LA ')'
       ' outfile=output dbms=csv replace'
    / ';'
    /  '  delimiter=";";'
    /  'run;'
  ;
run;

%include code / source2;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note you can use the FILENAME= option on the FILE statement to generate all of the delimited files in one pass of a single data step without all of the other rigmarole.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Aug 2019 19:20:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/quoting-issues/m-p/581241#M165177</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-08-14T19:20:58Z</dc:date>
    </item>
    <item>
      <title>Re: quoting issues</title>
      <link>https://communities.sas.com/t5/SAS-Programming/quoting-issues/m-p/581249#M165181</link>
      <description>Can you use CALL EXECUTE and a data step instead? That would generate no issues that I can see and would avoid the PROC SQL step as well as macro variables or macros or having to include the code either.</description>
      <pubDate>Wed, 14 Aug 2019 19:01:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/quoting-issues/m-p/581249#M165181</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-08-14T19:01:14Z</dc:date>
    </item>
    <item>
      <title>Re: quoting issues</title>
      <link>https://communities.sas.com/t5/SAS-Programming/quoting-issues/m-p/581271#M165195</link>
      <description>&lt;P&gt;If you need to create dynamic code from a dataset, use call execute() in a data step.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Aug 2019 20:05:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/quoting-issues/m-p/581271#M165195</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-08-14T20:05:36Z</dc:date>
    </item>
    <item>
      <title>Re: quoting issues</title>
      <link>https://communities.sas.com/t5/SAS-Programming/quoting-issues/m-p/581275#M165197</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Can you use CALL EXECUTE and a data step instead? That would generate no issues that I can see and would avoid the PROC SQL step as well as macro variables or macros or having to include the code either.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;But&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/127222"&gt;@acordes&lt;/a&gt;&amp;nbsp;said his code works, so I don't see the point of re-coding this using CALL EXECUTE. Maybe the next time he needs to do something similar, then he can use CALL EXECUTE.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Aug 2019 20:12:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/quoting-issues/m-p/581275#M165197</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-08-14T20:12:28Z</dc:date>
    </item>
    <item>
      <title>Re: quoting issues</title>
      <link>https://communities.sas.com/t5/SAS-Programming/quoting-issues/m-p/587168#M167677</link>
      <description>&lt;P&gt;What does&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token statement"&gt;filename&lt;/SPAN&gt; :&lt;SPAN class="token punctuation"&gt;$&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;quote&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;do?&lt;/P&gt;</description>
      <pubDate>Mon, 09 Sep 2019 09:16:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/quoting-issues/m-p/587168#M167677</guid>
      <dc:creator>acordes</dc:creator>
      <dc:date>2019-09-09T09:16:59Z</dc:date>
    </item>
    <item>
      <title>Re: quoting issues</title>
      <link>https://communities.sas.com/t5/SAS-Programming/quoting-issues/m-p/587169#M167678</link>
      <description>&lt;P&gt;Thank you, I use call execute quite often and I feel comfortable with it as long it doesn't rely on quoting stuff...&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Sep 2019 09:18:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/quoting-issues/m-p/587169#M167678</guid>
      <dc:creator>acordes</dc:creator>
      <dc:date>2019-09-09T09:18:31Z</dc:date>
    </item>
    <item>
      <title>Re: quoting issues</title>
      <link>https://communities.sas.com/t5/SAS-Programming/quoting-issues/m-p/587202#M167692</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/127222"&gt;@acordes&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;What does&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token statement"&gt;filename&lt;/SPAN&gt; :&lt;SPAN class="token punctuation"&gt;$&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;quote&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;do?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It is PART of the PUT statement. FILENAME is the name of variable.&amp;nbsp; $QUOTE. is the format to use when putting the variable. The colon modifier says to continue to use the list mode of the put statement instead of formatted mode, even though there is a format specification.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Sep 2019 11:13:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/quoting-issues/m-p/587202#M167692</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-09-09T11:13:59Z</dc:date>
    </item>
  </channel>
</rss>

