<?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: program error: how to create variable with different suffix with Macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/program-error-how-to-create-variable-with-different-suffix-with/m-p/266112#M269291</link>
    <description>Thank you for pointing our my type. But it seems to have other problem with the loop.</description>
    <pubDate>Mon, 25 Apr 2016 17:05:49 GMT</pubDate>
    <dc:creator>Crystal_F</dc:creator>
    <dc:date>2016-04-25T17:05:49Z</dc:date>
    <item>
      <title>program error: how to create variable with different suffix with Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/program-error-how-to-create-variable-with-different-suffix-with/m-p/266094#M269288</link>
      <description>&lt;P&gt;I have a problem to create new variables with different suffix. I'm hoping there is someone here could help me debug and correct the code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My plan is to generate 36 different&amp;nbsp;categorical variables&amp;nbsp;based on the similar criteria, i.e. therapy type, duration and setting. For example, if a patient had physical therapy in inpatient setting within a year since the index date, then it was coded to &lt;FONT face="Courier New" size="2"&gt;subpop_phy_1yr_ip_irf=1; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;The logic is like below:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;if subpop=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt; and sum_phy_mins_1yr_ip_irf &amp;gt;&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;0&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;then&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; subpop_phy_1yr_ip_irf=1;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;else.....&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;Similarily, if a patient had speech therapy in outpatient setting within 30 day since the index date, then a new variable subpop_ST_30day_op is created and coded to 1.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;My code is as follows:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;CODE class=" language-sas"&gt;%macro create_flagvar(therapy, duration, setting);
  %let n1=%sysfunc(countw(&amp;amp;therapy));
  %let n2=%sysfunc(countw(&amp;amp;duration));
  %let n3=%sysfunc(countw(&amp;amp;setting));

  data temp3.catpop1;
    set temp3.catpop;
     %do i=1 %to &amp;amp;n1;
       %let thearpy = %scan(&amp;amp;therapy,&amp;amp;i);
          %do j=1 %to &amp;amp;n2;
             %let duration = %scan(&amp;amp;duration,&amp;amp;j);
			    %do k=1 %to &amp;amp;n3;
                   %let setting = %scan(&amp;amp;setting,&amp;amp;k);
				   if subpop=1 and sum_&amp;amp;therapy._mins_&amp;amp;duration._&amp;amp;setting.&amp;gt;0 then subpop_&amp;amp;therapy._&amp;amp;duration._&amp;amp;setting=1;
                   else if subpop=1 and sum_&amp;amp;therapy._mins_&amp;amp;duration._&amp;amp;setting.=0 then subpop_&amp;amp;therapy._&amp;amp;duration._&amp;amp;setting.=2;
                   else if subpop=2 and sum_&amp;amp;therapy._mins_&amp;amp;duration._&amp;amp;setting.&amp;gt;0 then subpop_&amp;amp;therapy._&amp;amp;duration._&amp;amp;setting.=3;
                   else if subpop=2 and sum_&amp;amp;therapy._mins_&amp;amp;duration._&amp;amp;setting.=0 then subpop_&amp;amp;therapy._&amp;amp;duration._&amp;amp;setting.=4;
	               else if flag_98benes=1 and subpop=3 and sum_&amp;amp;therapy._mins_&amp;amp;duration._&amp;amp;setting.&amp;gt;0 then subpop_&amp;amp;therapy._&amp;amp;duration._&amp;amp;setting.=5;
	               else if flag_98benes=1 and subpop=3 and sum_&amp;amp;therapy._mins_&amp;amp;duration._&amp;amp;setting.=0 then subpop_&amp;amp;therapy._&amp;amp;duration._&amp;amp;setting.=6;
                   else subpop_&amp;amp;therapy._&amp;amp;duration._&amp;amp;setting.=7;
				   %end;
		       %end;
			%end;
	run;
%mend;

%create_flagvar(phy OT ST,1yr 30day 90day,ip_irf op snf hha);&lt;/CODE&gt;&lt;/FONT&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;The log shows something like below:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;NOTE: Line generated by the macro variable "SETTING".&lt;/P&gt;&lt;P&gt;1 sum_phy OT ST_mins_1yr_ip_irf&lt;/P&gt;&lt;P&gt;--&lt;/P&gt;&lt;P&gt;388&lt;/P&gt;&lt;P&gt;202&lt;/P&gt;&lt;P&gt;NOTE: Line generated by the macro variable "SETTING".&lt;/P&gt;&lt;P&gt;1 subpop_phy OT ST_1yr_ip_irf&lt;/P&gt;&lt;P&gt;----------&lt;/P&gt;&lt;P&gt;180&lt;/P&gt;&lt;P&gt;NOTE: Line generated by the macro variable "SETTING".&lt;/P&gt;&lt;P&gt;1 sum_phy OT ST_mins_1yr_ip_irf&lt;/P&gt;&lt;P&gt;--&lt;/P&gt;&lt;P&gt;388&lt;/P&gt;&lt;P&gt;202&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="2"&gt;Anyone know how to fix the problem? Your inputs are highly appreciated! Thank you!&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Apr 2016 16:30:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/program-error-how-to-create-variable-with-different-suffix-with/m-p/266094#M269288</guid>
      <dc:creator>Crystal_F</dc:creator>
      <dc:date>2016-04-25T16:30:07Z</dc:date>
    </item>
    <item>
      <title>Re: program error: how to create variable with different suffix with Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/program-error-how-to-create-variable-with-different-suffix-with/m-p/266099#M269289</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/82725"&gt;@Crystal_F﻿&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think, that's an easy one: Just correct the typo in&lt;/P&gt;
&lt;PRE&gt;%let the&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;ar&lt;/STRONG&gt;&lt;/FONT&gt;py = %scan(&amp;amp;therapy,&amp;amp;i);&lt;/PRE&gt;
&lt;P&gt;Edit: ... &lt;U&gt;and&lt;/U&gt; avoid overwriting the original values of the macro parameters with the extracted substrings!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit 2:&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;...
%do i=1 %to &amp;amp;n1; 
  %let ther = %scan(&amp;amp;therapy,&amp;amp;i); 
  %do j=1 %to &amp;amp;n2; 
    %let dur = %scan(&amp;amp;duration,&amp;amp;j); 
    %do k=1 %to &amp;amp;n3; 
      %let sett = %scan(&amp;amp;setting,&amp;amp;k); 
      if subpop=1 and sum_&amp;amp;ther._mins_&amp;amp;dur._&amp;amp;sett.&amp;gt;0 then subpop_&amp;amp;ther._&amp;amp;dur._&amp;amp;sett=1;
...&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 25 Apr 2016 16:59:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/program-error-how-to-create-variable-with-different-suffix-with/m-p/266099#M269289</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-04-25T16:59:36Z</dc:date>
    </item>
    <item>
      <title>Re: program error: how to create variable with different suffix with Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/program-error-how-to-create-variable-with-different-suffix-with/m-p/266108#M269290</link>
      <description>&lt;P&gt;Your plan has a problem.&amp;nbsp; Look what happens when you execute:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let duration = scan(&amp;amp;duration, &amp;amp;j);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This statement replaces &amp;amp;DURATION.&amp;nbsp; It used to contain a set of words, and now it contains only 1.&amp;nbsp; So the next time %LET executes, trying to read the second word from &amp;amp;DURATION, there is no second word.&amp;nbsp; %SCAN returns a blank.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can switch the %LET statements:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let ther = %scan(&amp;amp;therapy, &amp;amp;i);&lt;/P&gt;
&lt;P&gt;%let dur = %scan(&amp;amp;duration, &amp;amp;j);&lt;/P&gt;
&lt;P&gt;%let set = %scan(&amp;amp;setting, &amp;amp;k);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then refer to the new, shorter macro variable names in all the IF/THEN statements.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Apr 2016 16:59:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/program-error-how-to-create-variable-with-different-suffix-with/m-p/266108#M269290</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-04-25T16:59:19Z</dc:date>
    </item>
    <item>
      <title>Re: program error: how to create variable with different suffix with Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/program-error-how-to-create-variable-with-different-suffix-with/m-p/266112#M269291</link>
      <description>Thank you for pointing our my type. But it seems to have other problem with the loop.</description>
      <pubDate>Mon, 25 Apr 2016 17:05:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/program-error-how-to-create-variable-with-different-suffix-with/m-p/266112#M269291</guid>
      <dc:creator>Crystal_F</dc:creator>
      <dc:date>2016-04-25T17:05:49Z</dc:date>
    </item>
    <item>
      <title>Re: program error: how to create variable with different suffix with Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/program-error-how-to-create-variable-with-different-suffix-with/m-p/266116#M269292</link>
      <description>Thanks for sharing your thoughts. I did check with number of words. Duration has 3 words there: 1yr 30day 90day. I guess the problem is due to the incorrect loop. After I correct the typo, the log shows:&lt;BR /&gt;NOTE: Variable sum_phy_mins_1yr_ is uninitialized.&lt;BR /&gt;NOTE: Variable sum_phy_mins__ is uninitialized.&lt;BR /&gt;NOTE: Variable sum__mins__ is uninitialized.&lt;BR /&gt;</description>
      <pubDate>Mon, 25 Apr 2016 17:10:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/program-error-how-to-create-variable-with-different-suffix-with/m-p/266116#M269292</guid>
      <dc:creator>Crystal_F</dc:creator>
      <dc:date>2016-04-25T17:10:59Z</dc:date>
    </item>
    <item>
      <title>Re: program error: how to create variable with different suffix with Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/program-error-how-to-create-variable-with-different-suffix-with/m-p/266119#M269293</link>
      <description>Edit 2 is a good point. Sorry I didn't pay attention to this before. Thanks! I'll give it a try!</description>
      <pubDate>Mon, 25 Apr 2016 17:13:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/program-error-how-to-create-variable-with-different-suffix-with/m-p/266119#M269293</guid>
      <dc:creator>Crystal_F</dc:creator>
      <dc:date>2016-04-25T17:13:23Z</dc:date>
    </item>
    <item>
      <title>Re: program error: how to create variable with different suffix with Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/program-error-how-to-create-variable-with-different-suffix-with/m-p/266131#M269294</link>
      <description>&lt;P&gt;Looks like something is processing a blank value for Setting which would be a side effect of&lt;/P&gt;
&lt;P&gt;%let setting = scan(&amp;amp;setting,&amp;amp;k)&lt;/P&gt;
&lt;P&gt;as after the first pass (k=1) Setting has been set to only have one value- the first scan.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or not initializing the "corrected" other variable you may begusing in creating the Sum_&amp;amp;therapy etc variable. Check spellings.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Apr 2016 19:15:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/program-error-how-to-create-variable-with-different-suffix-with/m-p/266131#M269294</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-04-25T19:15:27Z</dc:date>
    </item>
    <item>
      <title>Re: program error: how to create variable with different suffix with Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/program-error-how-to-create-variable-with-different-suffix-with/m-p/266154#M269295</link>
      <description>Now I got your point! It works! Thank you for your help!</description>
      <pubDate>Mon, 25 Apr 2016 18:30:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/program-error-how-to-create-variable-with-different-suffix-with/m-p/266154#M269295</guid>
      <dc:creator>Crystal_F</dc:creator>
      <dc:date>2016-04-25T18:30:46Z</dc:date>
    </item>
    <item>
      <title>Re: program error: how to create variable with different suffix with Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/program-error-how-to-create-variable-with-different-suffix-with/m-p/266155#M269296</link>
      <description>Thank you for the cool explanation! Now my problem is fixed with all people's help here. Thanks a lot.</description>
      <pubDate>Mon, 25 Apr 2016 18:31:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/program-error-how-to-create-variable-with-different-suffix-with/m-p/266155#M269296</guid>
      <dc:creator>Crystal_F</dc:creator>
      <dc:date>2016-04-25T18:31:52Z</dc:date>
    </item>
  </channel>
</rss>

