<?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: listing a macro character value in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/listing-a-macro-character-value/m-p/816970#M322499</link>
    <description>&lt;P&gt;Read the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/p1nhhymw6gxixvn1johcfl6kaygw.htm" target="_self"&gt;documentation&lt;/A&gt;.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put %scan(&amp;amp;utilvars,&amp;amp;i,%str( ),q)=%scan(&amp;amp;labvals,&amp;amp;i,%str( ),q)&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 07 Jun 2022 23:31:32 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2022-06-07T23:31:32Z</dc:date>
    <item>
      <title>listing a macro character value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/listing-a-macro-character-value/m-p/816969#M322498</link>
      <description>&lt;P&gt;This code lists several variable and intended labels.&amp;nbsp; &amp;nbsp;However, it won't print all of the fifth value ('Chapter 4'), I assume because of the space.&amp;nbsp; &amp;nbsp;What is the fix?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;27 %let utilvars=Util_Transp_YN Util_Dental_YN Util_Vision_YN Util_Hearing_YN Util_Ch4_YN Util_Other_YN;&lt;BR /&gt;28 %let labvals='Transportation' 'Dental' 'Vision' 'Hearing' 'Chapter 4' 'Other';&lt;BR /&gt;29&lt;BR /&gt;30 %macro set_labs;&lt;BR /&gt;31 %do i=1 %to 5;&lt;BR /&gt;32 %put %scan(&amp;amp;utilvars,&amp;amp;i)=%qscan(&amp;amp;labvals,&amp;amp;i);&lt;BR /&gt;33 %end;&lt;BR /&gt;34 %mend;&lt;BR /&gt;35 %set_labs&lt;BR /&gt;Util_Transp_YN='Transportation'&lt;BR /&gt;Util_Dental_YN='Dental'&lt;BR /&gt;Util_Vision_YN='Vision'&lt;BR /&gt;Util_Hearing_YN='Hearing'&lt;BR /&gt;Util_Ch4_YN='Chapter&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jun 2022 23:14:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/listing-a-macro-character-value/m-p/816969#M322498</guid>
      <dc:creator>Batman</dc:creator>
      <dc:date>2022-06-07T23:14:44Z</dc:date>
    </item>
    <item>
      <title>Re: listing a macro character value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/listing-a-macro-character-value/m-p/816970#M322499</link>
      <description>&lt;P&gt;Read the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/p1nhhymw6gxixvn1johcfl6kaygw.htm" target="_self"&gt;documentation&lt;/A&gt;.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put %scan(&amp;amp;utilvars,&amp;amp;i,%str( ),q)=%scan(&amp;amp;labvals,&amp;amp;i,%str( ),q)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Jun 2022 23:31:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/listing-a-macro-character-value/m-p/816970#M322499</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-06-07T23:31:32Z</dc:date>
    </item>
    <item>
      <title>Re: listing a macro character value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/listing-a-macro-character-value/m-p/816995#M322513</link>
      <description>&lt;P&gt;Quotes as part of macro variables may cause any number of syntax issues.&lt;/P&gt;
&lt;P&gt;And you've just discovered one of the issues with space delimited data with embedded spaces.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;An alternate approach:&lt;/P&gt;
&lt;PRE&gt;%let utilvars=Util_Transp_YN Util_Dental_YN Util_Vision_YN Util_Hearing_YN Util_Ch4_YN Util_Other_YN;
%let labvals=Transportation|Dental|Vision|Hearing|Chapter 4|Other;

%macro set_labs;
   %do i=1 %to %sysfunc(countw(&amp;amp;utilvars.));
      %put %scan(&amp;amp;utilvars,&amp;amp;i)="%scan(&amp;amp;labvals,&amp;amp;i,|)";
   %end;
%mend;
%set_labs&lt;/PRE&gt;
&lt;P&gt;Use a specific known delimiter such as the | character. There are reasons involving passing values as parameters that make using commas not as nice. Then use that character as a parameter in the %scan (or %qscan if needed).&lt;/P&gt;
&lt;P&gt;Note use of the function %sysfunc to allow the data step function to COUNT the number of words in your Utilvars variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Depending on how complex a program is you could spend a significant amount of time trying to figure out why "I added variable XXXXX to the list, why is the label not applied?" or "Where is this line " =' ' " coming from" because you don't remember or see that you have fixed iteration in the %do loop and are processing too few or too many values that should be in utilvar.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jun 2022 05:05:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/listing-a-macro-character-value/m-p/816995#M322513</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-06-08T05:05:23Z</dc:date>
    </item>
  </channel>
</rss>

