<?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: Using macros to code for missing data in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Using-macros-to-code-for-missing-data/m-p/592899#M15425</link>
    <description>&lt;P&gt;I think using array will be better.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data work.drake;&lt;BR /&gt;set Theresa.drake;&lt;BR /&gt;array missng (*) Al_LFFQ Cal_LFFQ Carb_LFFQ Chol_LFFQ Cu_LFFQ E_LFFQ Fat_LFFQ Fe_LFFQ Fibre_LFFQ&lt;BR /&gt;Fola_LFFQ Fru_LFFQ Glu_LFFQ I_LFFQ K_LFFQ Lact_FFQ MUFA_LFFQ Mg_LFFQ Mn_LFFQ N_LFFQ NiacE_LFFQ&lt;BR /&gt;Niac_LFFQ PUFA_LFFQ P_LFFQ Prot_LFFQ Ret_LFFQ Ribof_LFFQ SFA_LFFQ Se_LFFQ Star_LFFQ Suc_LFFQ&lt;BR /&gt;TVitA_LFFQ Thia_LFFQ VitB12_LFFQ VitB6_LFFQ VitC_LFFQ VitD_LFFQ VitE_LFFQ Zn_LFFQ b_C_LFFQ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;do i=1 to dim(missng);&lt;/P&gt;&lt;P&gt;&amp;nbsp; if missng(i)=0 then missng(i)=.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; else missng(i)=missng(i);&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;</description>
    <pubDate>Tue, 01 Oct 2019 04:26:41 GMT</pubDate>
    <dc:creator>hlnquynh</dc:creator>
    <dc:date>2019-10-01T04:26:41Z</dc:date>
    <item>
      <title>Using macros to code for missing data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-macros-to-code-for-missing-data/m-p/592896#M15424</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;I'm trying to set the zeros in my dataset to missing, so SAS doesn't state it as my minimum value when I run proc means etc.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;I have about 40 variables so I've used macros as follows:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;%let xlist= Al_LFFQ Cal_LFFQ Carb_LFFQ Chol_LFFQ Cu_LFFQ E_LFFQ Fat_LFFQ Fe_LFFQ Fibre_LFFQ&lt;BR /&gt;Fola_LFFQ Fru_LFFQ Glu_LFFQ I_LFFQ K_LFFQ Lact_FFQ MUFA_LFFQ Mg_LFFQ Mn_LFFQ N_LFFQ NiacE_LFFQ&lt;BR /&gt;Niac_LFFQ PUFA_LFFQ P_LFFQ Prot_LFFQ Ret_LFFQ Ribof_LFFQ SFA_LFFQ Se_LFFQ Star_LFFQ Suc_LFFQ&lt;BR /&gt;TVitA_LFFQ Thia_LFFQ VitB12_LFFQ VitB6_LFFQ VitC_LFFQ VitD_LFFQ VitE_LFFQ Zn_LFFQ b_C_LFFQ;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;/*coding&amp;nbsp;0 values to missing*/&lt;BR /&gt;data work.drake;&lt;BR /&gt;&amp;nbsp; set Theresa.drake;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; if &amp;amp;xlist=0 then &amp;amp;xlist=.;&lt;BR /&gt;&amp;nbsp; run;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;I get an error code as below when I run it." Could you please help? Thanks&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*coding 0 values to missing*/&lt;/P&gt;&lt;P&gt;327 data work.drake;&lt;/P&gt;&lt;P&gt;328 set Theresa.drake;&lt;/P&gt;&lt;P&gt;329&amp;nbsp;&lt;FONT color="#000000" face="Calibri" size="3"&gt;if &amp;amp;xlist=0 then &amp;amp;xlist=.;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;NOTE: Line generated by the macro variable "XLIST".&lt;/P&gt;&lt;P&gt;1 Al_LFFQ Cal_LFFQ Carb_LFFQ Chol_LFFQ Cu_LFFQ E_LFFQ Fat_LFFQ Fe_LFFQ Fibre_LFFQ Fola_LFFQ&lt;/P&gt;&lt;P&gt;--------&lt;/P&gt;&lt;P&gt;388&lt;/P&gt;&lt;P&gt;76&lt;/P&gt;&lt;P&gt;1 ! Fru_LFFQ Glu_LFFQ I_LFFQ K_LFFQ Lact_FFQ MUFA_LFFQ Mg_LFFQ Mn_LFFQ N_LFFQ NiacE_LFFQ&lt;/P&gt;&lt;P&gt;1 ! Niac_LFFQ PUFA_LFFQ P_LFFQ Prot_LFFQ Ret_LFFQ Ribof_LFFQ SFA_LFFQ Se_LFFQ&lt;/P&gt;&lt;P&gt;ERROR 388-185: Expecting an arithmetic operator.&lt;/P&gt;&lt;P&gt;ERROR 76-322: Syntax error, statement will b&lt;/P&gt;</description>
      <pubDate>Tue, 01 Oct 2019 03:22:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-macros-to-code-for-missing-data/m-p/592896#M15424</guid>
      <dc:creator>catch18</dc:creator>
      <dc:date>2019-10-01T03:22:07Z</dc:date>
    </item>
    <item>
      <title>Re: Using macros to code for missing data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-macros-to-code-for-missing-data/m-p/592899#M15425</link>
      <description>&lt;P&gt;I think using array will be better.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data work.drake;&lt;BR /&gt;set Theresa.drake;&lt;BR /&gt;array missng (*) Al_LFFQ Cal_LFFQ Carb_LFFQ Chol_LFFQ Cu_LFFQ E_LFFQ Fat_LFFQ Fe_LFFQ Fibre_LFFQ&lt;BR /&gt;Fola_LFFQ Fru_LFFQ Glu_LFFQ I_LFFQ K_LFFQ Lact_FFQ MUFA_LFFQ Mg_LFFQ Mn_LFFQ N_LFFQ NiacE_LFFQ&lt;BR /&gt;Niac_LFFQ PUFA_LFFQ P_LFFQ Prot_LFFQ Ret_LFFQ Ribof_LFFQ SFA_LFFQ Se_LFFQ Star_LFFQ Suc_LFFQ&lt;BR /&gt;TVitA_LFFQ Thia_LFFQ VitB12_LFFQ VitB6_LFFQ VitC_LFFQ VitD_LFFQ VitE_LFFQ Zn_LFFQ b_C_LFFQ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;do i=1 to dim(missng);&lt;/P&gt;&lt;P&gt;&amp;nbsp; if missng(i)=0 then missng(i)=.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; else missng(i)=missng(i);&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Oct 2019 04:26:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-macros-to-code-for-missing-data/m-p/592899#M15425</guid>
      <dc:creator>hlnquynh</dc:creator>
      <dc:date>2019-10-01T04:26:41Z</dc:date>
    </item>
    <item>
      <title>Re: Using macros to code for missing data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-macros-to-code-for-missing-data/m-p/592911#M15426</link>
      <description>&lt;P&gt;I tried your suggestion here, but instead of changing the zeros in the dataset to . a new variable (i) was created and every observation in this new variable was given .&lt;/P&gt;</description>
      <pubDate>Tue, 01 Oct 2019 03:55:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-macros-to-code-for-missing-data/m-p/592911#M15426</guid>
      <dc:creator>catch18</dc:creator>
      <dc:date>2019-10-01T03:55:19Z</dc:date>
    </item>
    <item>
      <title>Re: Using macros to code for missing data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-macros-to-code-for-missing-data/m-p/592914#M15427</link>
      <description>Sorry, I have updated the answer. Please try again.</description>
      <pubDate>Tue, 01 Oct 2019 04:27:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-macros-to-code-for-missing-data/m-p/592914#M15427</guid>
      <dc:creator>hlnquynh</dc:creator>
      <dc:date>2019-10-01T04:27:56Z</dc:date>
    </item>
    <item>
      <title>Re: Using macros to code for missing data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-macros-to-code-for-missing-data/m-p/592929#M15432</link>
      <description>&lt;P&gt;You will have to write a loop to check each variable separately. Are all numeric variable from &lt;FONT size="3" face="Calibri" color="#000000"&gt;Theresa.drake&lt;/FONT&gt; in xList? If that is the case you can do something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.drake;
  set Theresa.drake;
  array nums _numeric_;

  do i = 1 to dim(nums);
    if nums[i] = 0 then nums[i] = .;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If not: replace _numeric_ with &amp;amp;xList.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Oct 2019 06:24:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-macros-to-code-for-missing-data/m-p/592929#M15432</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2019-10-01T06:24:12Z</dc:date>
    </item>
    <item>
      <title>Re: Using macros to code for missing data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-macros-to-code-for-missing-data/m-p/593000#M15446</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/293117"&gt;@catch18&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Calibri" size="3" color="#000000"&gt;I'm trying to set the zeros in my dataset to missing, so SAS doesn't state it as my minimum value when I run proc means etc.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Calibri" size="3" color="#000000"&gt;I have about 40 variables so I've used macros as follows:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Calibri" size="3" color="#000000"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Calibri" size="3" color="#000000"&gt;%let xlist= Al_LFFQ Cal_LFFQ Carb_LFFQ Chol_LFFQ Cu_LFFQ E_LFFQ Fat_LFFQ Fe_LFFQ Fibre_LFFQ&lt;BR /&gt;Fola_LFFQ Fru_LFFQ Glu_LFFQ I_LFFQ K_LFFQ Lact_FFQ MUFA_LFFQ Mg_LFFQ Mn_LFFQ N_LFFQ NiacE_LFFQ&lt;BR /&gt;Niac_LFFQ PUFA_LFFQ P_LFFQ Prot_LFFQ Ret_LFFQ Ribof_LFFQ SFA_LFFQ Se_LFFQ Star_LFFQ Suc_LFFQ&lt;BR /&gt;TVitA_LFFQ Thia_LFFQ VitB12_LFFQ VitB6_LFFQ VitC_LFFQ VitD_LFFQ VitE_LFFQ Zn_LFFQ b_C_LFFQ;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Calibri" size="3" color="#000000"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Calibri" size="3" color="#000000"&gt;/*coding&amp;nbsp;0 values to missing*/&lt;BR /&gt;data work.drake;&lt;BR /&gt;&amp;nbsp; set Theresa.drake;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; if &amp;amp;xlist=0 then &amp;amp;xlist=.;&lt;BR /&gt;&amp;nbsp; run;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Calibri" size="3" color="#000000"&gt;I get an error code as below when I run it." Could you please help? Thanks&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/*coding 0 values to missing*/&lt;/P&gt;
&lt;P&gt;327 data work.drake;&lt;/P&gt;
&lt;P&gt;328 set Theresa.drake;&lt;/P&gt;
&lt;P&gt;329&amp;nbsp;&lt;FONT face="Calibri" size="3" color="#000000"&gt;if &amp;amp;xlist=0 then &amp;amp;xlist=.;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;NOTE: Line generated by the macro variable "XLIST".&lt;/P&gt;
&lt;P&gt;1 Al_LFFQ Cal_LFFQ Carb_LFFQ Chol_LFFQ Cu_LFFQ E_LFFQ Fat_LFFQ Fe_LFFQ Fibre_LFFQ Fola_LFFQ&lt;/P&gt;
&lt;P&gt;--------&lt;/P&gt;
&lt;P&gt;388&lt;/P&gt;
&lt;P&gt;76&lt;/P&gt;
&lt;P&gt;1 ! Fru_LFFQ Glu_LFFQ I_LFFQ K_LFFQ Lact_FFQ MUFA_LFFQ Mg_LFFQ Mn_LFFQ N_LFFQ NiacE_LFFQ&lt;/P&gt;
&lt;P&gt;1 ! Niac_LFFQ PUFA_LFFQ P_LFFQ Prot_LFFQ Ret_LFFQ Ribof_LFFQ SFA_LFFQ Se_LFFQ&lt;/P&gt;
&lt;P&gt;ERROR 388-185: Expecting an arithmetic operator.&lt;/P&gt;
&lt;P&gt;ERROR 76-322: Syntax error, statement will b&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Macro variables perform text substitution, the value of the macro variable is substituted in place of &amp;amp;xlist when SAS runs, and this substitution &lt;STRONG&gt;MUST&lt;/STRONG&gt; result in legal valid working SAS code. So, the advice here would be to get the code to work for two variables without macros and without macro variables. If your code won't work without macros and without macro variables, then it will never work with macros and with macro variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Specifically, this is the code that is created when you run the program:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if Al_LFFQ Cal_LFFQ Carb_LFFQ Chol_LFFQ Cu_LFFQ E_LFFQ Fat_LFFQ Fe_LFFQ Fibre_LFFQ = 0 then&amp;nbsp;...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and this is not legal SAS code. I hope you see why this is not legal SAS code and will not work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, as mentioned, the use of ARRAYs here would be superior to macro variables which are not needed for this problem, and so the complications and difficulties of using macro variables also are not needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Oct 2019 12:09:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-macros-to-code-for-missing-data/m-p/593000#M15446</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-10-01T12:09:44Z</dc:date>
    </item>
    <item>
      <title>Re: Using macros to code for missing data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-macros-to-code-for-missing-data/m-p/593088#M15467</link>
      <description>&lt;P&gt;Many thanks.&lt;/P&gt;&lt;P&gt;This has worked but additionally, it has created an unwanted&amp;nbsp;(I) variable and given each observation 41 in this variable. I'm not familiar with array so not sure if this is expected?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Oct 2019 16:16:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-macros-to-code-for-missing-data/m-p/593088#M15467</guid>
      <dc:creator>catch18</dc:creator>
      <dc:date>2019-10-01T16:16:18Z</dc:date>
    </item>
    <item>
      <title>Re: Using macros to code for missing data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-macros-to-code-for-missing-data/m-p/593089#M15468</link>
      <description>&lt;P&gt;Thank you Paige Miller.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Oct 2019 16:17:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-macros-to-code-for-missing-data/m-p/593089#M15468</guid>
      <dc:creator>catch18</dc:creator>
      <dc:date>2019-10-01T16:17:26Z</dc:date>
    </item>
    <item>
      <title>Re: Using macros to code for missing data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-macros-to-code-for-missing-data/m-p/593099#M15471</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/293117"&gt;@catch18&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Many thanks.&lt;/P&gt;
&lt;P&gt;This has worked but additionally, it has created an unwanted&amp;nbsp;(I) variable and given each observation 41 in this variable. I'm not familiar with array so not sure if this is expected?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You can use the DROP statement to not output the variable I used to index into the array.&amp;nbsp; Note that its values is always 41 because your array had 40 variables.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;drop I;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or you could use the older DO OVER syntax.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array nums _numeric_;
do over nums ;
  if nums = 0 then nums = .;
end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 01 Oct 2019 16:29:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-macros-to-code-for-missing-data/m-p/593099#M15471</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-10-01T16:29:13Z</dc:date>
    </item>
    <item>
      <title>Re: Using macros to code for missing data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-macros-to-code-for-missing-data/m-p/593112#M15473</link>
      <description>&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Oct 2019 16:45:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-macros-to-code-for-missing-data/m-p/593112#M15473</guid>
      <dc:creator>catch18</dc:creator>
      <dc:date>2019-10-01T16:45:12Z</dc:date>
    </item>
  </channel>
</rss>

