<?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: Loop through class statement for proc surveylogistic in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Loop-through-class-statement-for-proc-surveylogistic/m-p/666863#M199598</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/298894"&gt;@sas_apprenant&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I guess you want to use blanks as delimiters, unless they belong to a substring in quotation marks. In this case you should add two more arguments to both the COUNTW function and the %SCAN function:&lt;/P&gt;
&lt;PRE&gt;%sysfunc(countw(&amp;amp;catclass&lt;STRONG&gt;&lt;FONT color="#00CCFF"&gt;,%str( ),q&lt;/FONT&gt;&lt;/STRONG&gt;))&lt;/PRE&gt;
&lt;PRE&gt;%scan(&amp;amp;catclass,&amp;amp;i&lt;STRONG&gt;&lt;FONT color="#00CCFF"&gt;,%str( ),q&lt;/FONT&gt;&lt;/STRONG&gt;)&lt;/PRE&gt;
&lt;P&gt;Otherwise, the embedded blanks and other characters ("default delimiters") would be treated as delimiters.&lt;/P&gt;</description>
    <pubDate>Fri, 03 Jul 2020 17:16:15 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2020-07-03T17:16:15Z</dc:date>
    <item>
      <title>Loop through class statement for proc surveylogistic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-through-class-statement-for-proc-surveylogistic/m-p/666844#M199588</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I am having a problem looping through a list for class statement in the proc surveylogistic step.&amp;nbsp; The code is below&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let catclass = agegrp(ref="40-49") raceth(ref="NH White") maritals(ref="Married") educat(ref="Some College/College Grad")&lt;BR /&gt;                wrkstat(ref="Employed")  income(ref="&amp;gt;= $50,000") insure(ref="No") hlthcost(ref="No")  doctor(ref="No") &lt;BR /&gt;                hltstat(ref="Excellent/Very Good");

%macro ccls();
%do i = 1 %to %sysfunc(countw(&amp;amp;catclass));
    %let logref = %scan(&amp;amp;catclass,&amp;amp;i);
%end;
%mend;
%ccls;&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;When I loop through it, I get this error (see below).&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;MLOGIC(REF): Beginning execution.&lt;BR /&gt;SYMBOLGEN: Macro variable CATCLASS resolves to&lt;BR /&gt;agegrp(ref="40-49") raceth(ref="NH White")&lt;BR /&gt;maritals(ref="Married")&lt;BR /&gt;educat(ref="Some College/College Grad")&lt;BR /&gt;wrkstat(ref="Employed") income(ref="&amp;gt;=&lt;BR /&gt;$50,000") insure(ref="No") hlthcost(ref="No")&lt;BR /&gt;doctor(ref="No") hltstat(ref="Excellent/Very&lt;BR /&gt;Good")&lt;BR /&gt;MLOGIC(REF): %DO loop beginning; index variable I; start value&lt;BR /&gt;is 1; stop value is 29; by value is 1.&lt;BR /&gt;MLOGIC(REF): %LET (variable name is LOGREF)&lt;BR /&gt;SYMBOLGEN: Macro variable CATCLASS resolves to&lt;BR /&gt;agegrp(ref="40-49") raceth(ref="NH White")&lt;BR /&gt;maritals(ref="Married")&lt;BR /&gt;educat(ref="Some College/College Grad")&lt;BR /&gt;wrkstat(ref="Employed") income(ref="&amp;gt;=&lt;BR /&gt;$50,000") insure(ref="No") hlthcost(ref="No")&lt;BR /&gt;doctor(ref="No") hltstat(ref="Excellent/Very&lt;BR /&gt;Good")&lt;BR /&gt;SYMBOLGEN: Macro variable I resolves to 1&lt;BR /&gt;MLOGIC(REF): %DO loop index variable I is now 2; loop will&lt;BR /&gt;iterate again.&lt;BR /&gt;MLOGIC(REF): %LET (variable name is LOGREF)&lt;BR /&gt;SYMBOLGEN: Macro variable CATCLASS resolves to&lt;BR /&gt;agegrp(ref="40-49") raceth(ref="NH White")&lt;BR /&gt;maritals(ref="Married")&lt;BR /&gt;educat(ref="Some College/College Grad")&lt;BR /&gt;wrkstat(ref="Employed") income(ref="&amp;gt;=&lt;BR /&gt;$50,000") insure(ref="No") hlthcost(ref="No")&lt;BR /&gt;doctor(ref="No") hltstat(ref="Excellent/Very&lt;BR /&gt;Good")&lt;BR /&gt;SYMBOLGEN: Macro variable I resolves to 2&lt;BR /&gt;ERROR: Literal contains unmatched quote.&lt;BR /&gt;ERROR: The macro REF will stop executing.&lt;BR /&gt;MLOGIC(REF): Ending execution.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Additionally, when I try it another way, I get another error. Code is below and error is after that&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let ref = "40-49" "NH White" "Married" "Some College/College Grad" "Employed" "&amp;gt;= $50,000" "No" "No" "No" "Excellent/Very Good";

%macro ref();
%do i = 1 %to %sysfunc(countw(&amp;amp;ref));
    %let logref = %scan(&amp;amp;ref,&amp;amp;i);
%end;
%mend;
%ref;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;MLOGIC(REF): Beginning execution.&lt;BR /&gt;SYMBOLGEN: Macro variable REF resolves to "40-49" "NH White"&lt;BR /&gt;"Married" "Some College/College Grad" "Employed"&lt;BR /&gt;"&amp;gt;= $50,000" "No" "No" "No" "Excellent/Very&lt;BR /&gt;Good"&lt;BR /&gt;MLOGIC(REF): %DO loop beginning; index variable I; start value&lt;BR /&gt;is 1; stop value is 19; by value is 1.&lt;BR /&gt;MLOGIC(REF): %LET (variable name is LOGREF)&lt;BR /&gt;SYMBOLGEN: Macro variable REF resolves to "40-49" "NH White"&lt;BR /&gt;"Married" "Some College/College Grad" "Employed"&lt;BR /&gt;"&amp;gt;= $50,000" "No" "No" "No" "Excellent/Very&lt;BR /&gt;Good"&lt;BR /&gt;SYMBOLGEN: Macro variable I resolves to 1&lt;BR /&gt;ERROR: Literal contains unmatched quote.&lt;BR /&gt;ERROR: The macro REF will stop executing.&lt;BR /&gt;MLOGIC(REF): Ending execution.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I figure this out?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the help.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jul 2020 15:27:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-through-class-statement-for-proc-surveylogistic/m-p/666844#M199588</guid>
      <dc:creator>sas_apprenant</dc:creator>
      <dc:date>2020-07-03T15:27:21Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through class statement for proc surveylogistic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-through-class-statement-for-proc-surveylogistic/m-p/666863#M199598</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/298894"&gt;@sas_apprenant&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I guess you want to use blanks as delimiters, unless they belong to a substring in quotation marks. In this case you should add two more arguments to both the COUNTW function and the %SCAN function:&lt;/P&gt;
&lt;PRE&gt;%sysfunc(countw(&amp;amp;catclass&lt;STRONG&gt;&lt;FONT color="#00CCFF"&gt;,%str( ),q&lt;/FONT&gt;&lt;/STRONG&gt;))&lt;/PRE&gt;
&lt;PRE&gt;%scan(&amp;amp;catclass,&amp;amp;i&lt;STRONG&gt;&lt;FONT color="#00CCFF"&gt;,%str( ),q&lt;/FONT&gt;&lt;/STRONG&gt;)&lt;/PRE&gt;
&lt;P&gt;Otherwise, the embedded blanks and other characters ("default delimiters") would be treated as delimiters.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jul 2020 17:16:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-through-class-statement-for-proc-surveylogistic/m-p/666863#M199598</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-07-03T17:16:15Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through class statement for proc surveylogistic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-through-class-statement-for-proc-surveylogistic/m-p/666940#M199645</link>
      <description>&lt;P&gt;I tried that and it resolves to nothing. What could be wrong?&lt;/P&gt;</description>
      <pubDate>Sat, 04 Jul 2020 13:55:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-through-class-statement-for-proc-surveylogistic/m-p/666940#M199645</guid>
      <dc:creator>sas_apprenant</dc:creator>
      <dc:date>2020-07-04T13:55:13Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through class statement for proc surveylogistic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-through-class-statement-for-proc-surveylogistic/m-p/666943#M199648</link>
      <description>&lt;P&gt;It depends on your code. The macros in your initial post overwrite the value of macro variable &lt;FONT face="courier new,courier"&gt;logref&lt;/FONT&gt; again and again with different substrings of &lt;FONT face="courier new,courier"&gt;&amp;amp;catclass&lt;/FONT&gt; or &lt;FONT face="courier new,courier"&gt;&amp;amp;ref&lt;/FONT&gt;, respectively. Therefore I assumed that these are only simplified code examples and that your real macros use those substrings in a more sensible way. To test my code I added a %PUT statement to the %DO loop:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let catclass = agegrp(ref="40-49") raceth(ref="NH White") maritals(ref="Married") educat(ref="Some College/College Grad")                wrkstat(ref="Employed")  income(ref="&amp;gt;= $50,000") insure(ref="No") hlthcost(ref="No")  doctor(ref="No")                 hltstat(ref="Excellent/Very Good");

%macro test;
%do i = 1 %to %sysfunc(countw(&amp;amp;catclass,%str( ),q));
  %let logref = %scan(&amp;amp;catclass,&amp;amp;i,%str( ),q);
  %put &amp;amp;i  &amp;amp;logref;
%end;
%mend;
%test&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result in the log:&lt;/P&gt;
&lt;PRE&gt;1  agegrp(ref="40-49")
2  raceth(ref="NH White")
3  maritals(ref="Married")
4  educat(ref="Some College/College Grad")
5  wrkstat(ref="Employed")
6  income(ref="&amp;gt;= $50,000")
7  insure(ref="No")
8  hlthcost(ref="No")
9  doctor(ref="No")
10  hltstat(ref="Excellent/Very Good")&lt;/PRE&gt;
&lt;P&gt;If you want to obtain different substrings (e.g., first &lt;FONT face="courier new,courier"&gt;agegrp&lt;/FONT&gt;, then &lt;FONT face="courier new,courier"&gt;(ref="40-49")&lt;/FONT&gt;, etc.), please let me know.&lt;/P&gt;</description>
      <pubDate>Sat, 04 Jul 2020 14:22:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-through-class-statement-for-proc-surveylogistic/m-p/666943#M199648</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-07-04T14:22:34Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through class statement for proc surveylogistic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-through-class-statement-for-proc-surveylogistic/m-p/666947#M199650</link>
      <description>&lt;P&gt;Can you show me how one would go about doing this (&lt;SPAN&gt;If you want to obtain different substrings (e.g., first&amp;nbsp;&lt;/SPAN&gt;&lt;FONT face="courier new,courier"&gt;agegrp&lt;/FONT&gt;&lt;SPAN&gt;, then&amp;nbsp;&lt;/SPAN&gt;&lt;FONT face="courier new,courier"&gt;(ref="40-49")&lt;/FONT&gt;&lt;SPAN&gt;, etc.), please let me know.)? I would like to learn.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thank you.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 04 Jul 2020 14:55:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-through-class-statement-for-proc-surveylogistic/m-p/666947#M199650</guid>
      <dc:creator>sas_apprenant</dc:creator>
      <dc:date>2020-07-04T14:55:12Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through class statement for proc surveylogistic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-through-class-statement-for-proc-surveylogistic/m-p/666949#M199652</link>
      <description>&lt;P&gt;You could split the value of &lt;FONT face="courier new,courier"&gt;logref&lt;/FONT&gt; further, e.g., using the %SCAN, %SUBSTR and %INDEX functions:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test2;
%do i = 1 %to %sysfunc(countw(&amp;amp;catclass,%str( ),q));
  %let logref = %scan(&amp;amp;catclass,&amp;amp;i,%str( ),q);
  %let varname = %scan(&amp;amp;logref,1,%str(%());
  %let refopt = %substr(&amp;amp;logref,%index(&amp;amp;logref,%str(%()));
  %put &amp;amp;i  &amp;amp;=logref  &amp;amp;=varname  &amp;amp;=refopt;
%end;
%mend;
%test2&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The unmatched parentheses require an extra percent sign (see documentation of&amp;nbsp;&lt;A href="https://documentation.sas.com/?docsetId=mcrolref&amp;amp;docsetTarget=p0pnc7p9n4h6g5n16g6js048nhfl.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en#p0guhqnlr7q0g2n18pdmg0p6b4up" target="_blank" rel="noopener"&gt;%STR and %NRSTR functions&lt;/A&gt;).&lt;/P&gt;</description>
      <pubDate>Sat, 04 Jul 2020 15:19:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-through-class-statement-for-proc-surveylogistic/m-p/666949#M199652</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-07-04T15:19:01Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through class statement for proc surveylogistic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-through-class-statement-for-proc-surveylogistic/m-p/666957#M199655</link>
      <description>&lt;P&gt;Just split the original on space and the substring on parentheses.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let catclass = agegrp(ref="40-49") raceth(ref="NH White") maritals(ref="Married") educat(ref="Some College/College Grad")                wrkstat(ref="Employed")  income(ref="&amp;gt;= $50,000") insure(ref="No") hlthcost(ref="No")  doctor(ref="No")

%macro test(list);
%local i var ref ;
%do i = 1 %to %sysfunc(countw(&amp;amp;list,%str( ),q));
  %let var = %scan(&amp;amp;catclass,&amp;amp;i,%str( ),q);
  %let ref = %scan(&amp;amp;var,2,());
  %let var = %scan(&amp;amp;var,1,());
  %put &amp;amp;=i &amp;amp;=var &amp;amp;=ref;
%end;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;PRE&gt;36   %test(&amp;amp;catclass);
I=1 VAR=agegrp REF=ref="40-49"
I=2 VAR=raceth REF=ref="NH White"
I=3 VAR=maritals REF=ref="Married"
I=4 VAR=educat REF=ref="Some College/College Grad"
I=5 VAR=wrkstat REF=ref="Employed"
I=6 VAR=income REF=ref="&amp;gt;= $50,000"
I=7 VAR=insure REF=ref="No"
I=8 VAR=hlthcost REF=ref="No"
I=9 VAR=doctor REF=ref="No"
I=10 VAR=hltstat REF=ref="Excellent/Very Good"&lt;/PRE&gt;
&lt;P&gt;You can add the parentheses back again if you want.&amp;nbsp; Or do another %SCAN() call to remove the REF= part.&amp;nbsp; &amp;nbsp;You could even add a %QSYSFUNC(DEQUOTE()) call to remove the quotes.&lt;/P&gt;</description>
      <pubDate>Sat, 04 Jul 2020 16:24:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-through-class-statement-for-proc-surveylogistic/m-p/666957#M199655</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-07-04T16:24:59Z</dc:date>
    </item>
  </channel>
</rss>

