<?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 How to separate whole sentences within a macro variable? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-separate-whole-sentences-within-a-macro-variable/m-p/877090#M346490</link>
    <description>&lt;P&gt;Hey guys,&lt;/P&gt;
&lt;P&gt;I am trying to produce a report that generates several tables and stores information out of an excel file. So far my code did what I wanted: It produced three tables that contained all the information in just the right format. Unfortunately, after going from my little example data to the real data I realised that my code does not work if my created macro variable "&amp;amp;frage" contains not just single words but whole sentences. Now I am wondering if I have to find another solution for my report. The working code and excel looks like this (excel "test_skalen_items_v2" attached):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc import
  datafile="yourpath\test_skalen_items_v2.xlsx"
  out=Skalen_Items
  dbms=xlsx
  replace;
run;

proc sql noprint;
  select distinct Frage into :fragen separated by " "
  from Skalen_Items;
quit;

%macro want;

%do i = 1 %to %sysfunc(countw(&amp;amp;fragen.));
%let frage = %scan(&amp;amp;fragen., &amp;amp;i.);

ods pdf file="yourpath\Table.pdf";
ods pdf startpage=now;


data &amp;amp;frage.(drop=Frage);
	set Skalen_Items(where=(Frage="&amp;amp;frage."));
run;

proc report data=&amp;amp;frage.;
	column Variable Antwortoption;
	define Antwortoption / "&amp;amp;frage.";
	compute Antwortoption;
		if Variable = "Kodierung" then call define(_col_ -1, "style", "style={font_weight=bold}");
	endcomp;
run; 

%end;
ods pdf close;
%mend want;
%want;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And if I use the excel "test_skalen_items_FAIL.xlsx" (also attached) the code does not work anymore. As you can see in the Excel, the column "Frage" does now contain not just the single words (e. g. Frage1) but whole sentences (e. g. Frage zwei jo).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To clarify again: Is it possible to create the tables as with my first excel but now with sentences (or: several words with spaces inbetween) or do I have to find a whole other solution for my report? I am thankful for any help!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards&lt;/P&gt;</description>
    <pubDate>Tue, 23 May 2023 14:57:17 GMT</pubDate>
    <dc:creator>_Manhattan</dc:creator>
    <dc:date>2023-05-23T14:57:17Z</dc:date>
    <item>
      <title>How to separate whole sentences within a macro variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-separate-whole-sentences-within-a-macro-variable/m-p/877090#M346490</link>
      <description>&lt;P&gt;Hey guys,&lt;/P&gt;
&lt;P&gt;I am trying to produce a report that generates several tables and stores information out of an excel file. So far my code did what I wanted: It produced three tables that contained all the information in just the right format. Unfortunately, after going from my little example data to the real data I realised that my code does not work if my created macro variable "&amp;amp;frage" contains not just single words but whole sentences. Now I am wondering if I have to find another solution for my report. The working code and excel looks like this (excel "test_skalen_items_v2" attached):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc import
  datafile="yourpath\test_skalen_items_v2.xlsx"
  out=Skalen_Items
  dbms=xlsx
  replace;
run;

proc sql noprint;
  select distinct Frage into :fragen separated by " "
  from Skalen_Items;
quit;

%macro want;

%do i = 1 %to %sysfunc(countw(&amp;amp;fragen.));
%let frage = %scan(&amp;amp;fragen., &amp;amp;i.);

ods pdf file="yourpath\Table.pdf";
ods pdf startpage=now;


data &amp;amp;frage.(drop=Frage);
	set Skalen_Items(where=(Frage="&amp;amp;frage."));
run;

proc report data=&amp;amp;frage.;
	column Variable Antwortoption;
	define Antwortoption / "&amp;amp;frage.";
	compute Antwortoption;
		if Variable = "Kodierung" then call define(_col_ -1, "style", "style={font_weight=bold}");
	endcomp;
run; 

%end;
ods pdf close;
%mend want;
%want;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And if I use the excel "test_skalen_items_FAIL.xlsx" (also attached) the code does not work anymore. As you can see in the Excel, the column "Frage" does now contain not just the single words (e. g. Frage1) but whole sentences (e. g. Frage zwei jo).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To clarify again: Is it possible to create the tables as with my first excel but now with sentences (or: several words with spaces inbetween) or do I have to find a whole other solution for my report? I am thankful for any help!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards&lt;/P&gt;</description>
      <pubDate>Tue, 23 May 2023 14:57:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-separate-whole-sentences-within-a-macro-variable/m-p/877090#M346490</guid>
      <dc:creator>_Manhattan</dc:creator>
      <dc:date>2023-05-23T14:57:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to separate whole sentences within a macro variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-separate-whole-sentences-within-a-macro-variable/m-p/877092#M346491</link>
      <description>&lt;P&gt;If you separate values by space and allow Countw to look at that value then the spaces are delimiters. Same with Scan or %scan.&lt;/P&gt;
&lt;P&gt;From the documentation of Countw:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;DIV class="xis-refDictEntry"&gt;
&lt;DIV class="xis-details"&gt;
&lt;DIV id="p1vu5ljm89ptv6n1wcv16s9jbenj" class="xis-subTopic"&gt;
&lt;DIV id="p010tub02xn6udn0zhxn7wik095p" class="xis-topicContent"&gt;
&lt;DIV id="n0r9d75qm5vppbn0zzamknoc6f27" class="xis-paragraph"&gt;If you use the &lt;FONT style="background-color: #fcdec0;"&gt;COUNTW&lt;/FONT&gt; function with only two arguments, the default delimiters depend on whether your computer uses ASCII or EBCDIC characters.
&lt;DIV class="xis-listUnordered"&gt;
&lt;UL&gt;
&lt;LI&gt;
&lt;DIV id="n0pwim87ric6ejn1uxaaemxltnbl" class="xis-item"&gt;
&lt;DIV id="p1j0z97pyrmr13n1osijo71rxt7a" class="xis-paraSimpleFirst"&gt;If your computer uses ASCII characters, then the default delimiters are as follows:&lt;/DIV&gt;
&lt;DIV id="n165p8dnduyv2nn14d1vse3j163a" class="xis-paraSimple"&gt;blank ! $ % &amp;amp; ( ) * + , - . / ; &amp;lt; ^ |&lt;/DIV&gt;
&lt;DIV id="n1jioswq56e6z6n1n07vuymxl0b6" class="xis-paraSimple"&gt;In ASCII environments that do not contain the ^ character, the SCAN function uses the ~ character instead.&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV id="n0i2loer55bijnn162nfbmeox3ca" class="xis-item"&gt;
&lt;DIV id="p0919kop5ok99vn1kbg6olfsd9fu" class="xis-paraSimpleFirst"&gt;If your computer uses EBCDIC characters, then the default delimiters are as follows:&lt;/DIV&gt;
&lt;DIV id="n0snopwlc432enn1vligialqjeo1" class="xis-paraSimple"&gt;blank ! $ % &amp;amp; ( ) * + , - . / ; &amp;lt; ¬ | ¢&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/LI&gt;
&lt;/UL&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So you pick a single character that does &lt;STRONG&gt;not&lt;/STRONG&gt; appear in the values of your text. You pick. I'm not looking XLSX from unknown sources. Then modify the Countw and Scan to use that character and SEPARATE the values with that character.&lt;/P&gt;
&lt;PRE&gt;proc sql noprint;
  select distinct Frage into :fragen separated by "&lt;FONT color="#FF0000"&gt;*&lt;/FONT&gt;"
  from Skalen_Items;
quit;

%macro want;

%do i = 1 %to %sysfunc(countw(&amp;amp;fragen.,&lt;FONT color="#FF0000"&gt;*&lt;/FONT&gt;));
%let frage = %scan(&amp;amp;fragen., &amp;amp;i.,&lt;FONT color="#FF0000"&gt;*&lt;/FONT&gt;);
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 May 2023 15:12:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-separate-whole-sentences-within-a-macro-variable/m-p/877092#M346491</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-05-23T15:12:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to separate whole sentences within a macro variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-separate-whole-sentences-within-a-macro-variable/m-p/877130#M346517</link>
      <description>&lt;P&gt;Also if you add quotes and use the Q option on COUNTW() and SCAN() then it does not matter if the delimiter is part of a value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And if you use single quotes to do the quoting it has the added value of protecting any macro triggers, &amp;amp; or %, that are in the strings.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select distinct quote(trim(Frage),"'") into :fragen separated by "*"
  from Skalen_Items
;
quit;

....


%do i = 1 %to %sysfunc(countw(&amp;amp;fragen.,*,q));
  %let frage = %scan(&amp;amp;fragen., &amp;amp;i.,*,q);
  ...
%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you need to remove the quotes use the DEQUOTE() function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  %let frage = %qsysfunc(dequote(%scan(&amp;amp;fragen., &amp;amp;i.,*,q)));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 23 May 2023 17:25:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-separate-whole-sentences-within-a-macro-variable/m-p/877130#M346517</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-05-23T17:25:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to separate whole sentences within a macro variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-separate-whole-sentences-within-a-macro-variable/m-p/877261#M346571</link>
      <description>Thank you! For future questions: what kind of format would be save to look at from unknown sources? CSV?</description>
      <pubDate>Wed, 24 May 2023 12:46:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-separate-whole-sentences-within-a-macro-variable/m-p/877261#M346571</guid>
      <dc:creator>_Manhattan</dc:creator>
      <dc:date>2023-05-24T12:46:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to separate whole sentences within a macro variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-separate-whole-sentences-within-a-macro-variable/m-p/877262#M346572</link>
      <description>Thank you Tom!</description>
      <pubDate>Wed, 24 May 2023 12:46:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-separate-whole-sentences-within-a-macro-variable/m-p/877262#M346572</guid>
      <dc:creator>_Manhattan</dc:creator>
      <dc:date>2023-05-24T12:46:58Z</dc:date>
    </item>
  </channel>
</rss>

