<?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: Macro error? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-error/m-p/537858#M147997</link>
    <description>Look into NMISS and CMISS functions.</description>
    <pubDate>Fri, 22 Feb 2019 20:52:51 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2019-02-22T20:52:51Z</dc:date>
    <item>
      <title>Macro error?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-error/m-p/537843#M147990</link>
      <description>&lt;P&gt;Hi all:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;I am looking for the NON-missing records in several numeric&amp;nbsp;variables.&amp;nbsp;&amp;nbsp; I have the codes below.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let vars = admitdt dischargedt 23hrstay hosp hospdt dob sex antimed rapidRT;

data want;
	set have;
	if &amp;amp;vars. ^= . ;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The error message is shown:&lt;/P&gt;
&lt;P&gt;WARNING: Apparent symbolic reference VARS not resolved.&lt;/P&gt;
&lt;P&gt;ERROR 386-185: Expecting an arithmetic expression.&lt;/P&gt;
&lt;P&gt;ERROR 200-322: The symbol is not recognized and will be ignored.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please advice how to fix it.&amp;nbsp;&amp;nbsp; Thanks.&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Feb 2019 20:53:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-error/m-p/537843#M147990</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2019-02-22T20:53:56Z</dc:date>
    </item>
    <item>
      <title>Re: Macro error?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-error/m-p/537851#M147993</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/67134"&gt;@ybz12003&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi all:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;I am looking for the NON-missing records in several numeric&amp;nbsp;variables.&amp;nbsp;&amp;nbsp; I have the codes below.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let vars = admitdt dischargedt 23hrstay hosp hospdt dob sex antimed rapidRT;

data want;
	set have;
	if vars. ^= . ;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The error message is shown:&lt;/P&gt;
&lt;P&gt;WARNING: Apparent symbolic reference VARS not resolved.&lt;/P&gt;
&lt;P&gt;ERROR 386-185: Expecting an arithmetic expression.&lt;/P&gt;
&lt;P&gt;ERROR 200-322: The symbol is not recognized and will be ignored.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please advice how to fix it.&amp;nbsp;&amp;nbsp; Thanks.&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Two issues. One is that I think you want to use&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if &amp;amp;vars.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;but you left out the ampersand.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The second issue is that even if you put in the ampersand, you still must have the macro variable resolve and produce LEGAL VALID SAS code. So if you use&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if &amp;amp;vars. ^= . ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This does not produce legal valid SAS code, because &amp;amp;vars is replaced with its value, and then&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if admitdt dischargedt 23hrstay hosp hospdt dob sex antimed rapidRT ^= .;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;is not legal valid SAS code. You have to fix the IF statement in such a way that it becomes legal valid SAS code. I'd give you an example, but I don't really know what you want as the output, and so I'd need to understand that before I can give you an example.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In any event, the best advice I can give you, and really the only path forward, is to start with a simple example, such as the case where you have only 2 variables, ADMITDT and DISCHARGEDT. Write SAS code for these two variables, without macros, run it so that you can confirm it works properly, and then creating and using a macro variable will be much simpler. Without working SAS code, you will not get far.&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>Fri, 22 Feb 2019 20:45:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-error/m-p/537851#M147993</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-02-22T20:45:26Z</dc:date>
    </item>
    <item>
      <title>Re: Macro error?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-error/m-p/537857#M147996</link>
      <description>&lt;P&gt;The variable name shown here are fake name I create.&amp;nbsp;&amp;nbsp; I did try the ones with separated order.&amp;nbsp;&amp;nbsp; For example, dob ^=. &amp;amp; sex ^=. .&amp;nbsp;&amp;nbsp;&amp;nbsp; With the code above is working.&amp;nbsp; However, I would like to create a macro variable list because I am not just look for two variables, a BUNCH of them instead.&amp;nbsp; Actually, I did add &amp;amp; in my actual codes.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Feb 2019 20:53:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-error/m-p/537857#M147996</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2019-02-22T20:53:22Z</dc:date>
    </item>
    <item>
      <title>Re: Macro error?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-error/m-p/537858#M147997</link>
      <description>Look into NMISS and CMISS functions.</description>
      <pubDate>Fri, 22 Feb 2019 20:52:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-error/m-p/537858#M147997</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-02-22T20:52:51Z</dc:date>
    </item>
    <item>
      <title>Re: Macro error?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-error/m-p/537860#M147999</link>
      <description>&lt;P&gt;As I said,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/67134"&gt;@ybz12003&lt;/a&gt;&amp;nbsp;, the place to start is to get an example working with just two variables and NO MACROs. Confirm that the code works. &lt;FONT color="#FF0000"&gt;Show us the working code.&lt;/FONT&gt; Then creating macros will be much much easier.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, given the brief example you show, there's really no need for macros here at all. Perhaps this is part of a much more complex problem where you might need macros, but this hasn't been demonstrated.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Feb 2019 21:09:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-error/m-p/537860#M147999</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-02-22T21:09:03Z</dc:date>
    </item>
    <item>
      <title>Re: Macro error?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-error/m-p/537864#M148000</link>
      <description>&lt;P&gt;Start with&amp;nbsp;&lt;EM&gt;working&lt;/EM&gt; SAS code, then replace the necessary parts with macro variables to make it dynamic.&lt;/P&gt;
&lt;P&gt;Use&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint mlogic symbolgen;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;when debugging macro code, and (Maxim 2)&amp;nbsp;&lt;EM&gt;read the log&lt;/EM&gt;. In its entirety.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Feb 2019 20:58:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-error/m-p/537864#M148000</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-02-22T20:58:03Z</dc:date>
    </item>
    <item>
      <title>Re: Macro error?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-error/m-p/537875#M148004</link>
      <description>&lt;P&gt;Below the codes&amp;nbsp;works.&amp;nbsp;&amp;nbsp; Basely, I need to list all of the variables name.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	set have;
	if admitdt ^= . 
		or dischargedt ^= . 
		or stay ^= . 
		or hosp ^= . 
		or hospdt ^= . 
		or dob ^= . 
		or sex ^= . 
		or disd ^= . 
		or antivir ^= . 
		or cxr ^= . 
		or rapid ^= . ;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;My final goal is&amp;nbsp;simplifying my typing the variables one by one.&amp;nbsp;&amp;nbsp; Thanks.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Feb 2019 21:17:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-error/m-p/537875#M148004</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2019-02-22T21:17:27Z</dc:date>
    </item>
    <item>
      <title>Re: Macro error?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-error/m-p/537878#M148005</link>
      <description>&lt;P&gt;Use NMISS(). It will count the number of missing and you don't want any.&amp;nbsp; This will work for a single variable or a list of variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if nmiss( of &amp;amp;VariableList.) &amp;gt; 0 then ....;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/67134"&gt;@ybz12003&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Below the codes&amp;nbsp;works.&amp;nbsp;&amp;nbsp; Basely, I need to list all of the variables name.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	set have;
	if admitdt ^= . 
		or dischargedt ^= . 
		or stay ^= . 
		or hosp ^= . 
		or hospdt ^= . 
		or dob ^= . 
		or sex ^= . 
		or disd ^= . 
		or antivir ^= . 
		or cxr ^= . 
		or rapid ^= . ;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;My final goal is&amp;nbsp;simplifying my typing the variables one by one.&amp;nbsp;&amp;nbsp; Thanks.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Feb 2019 21:21:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-error/m-p/537878#M148005</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-02-22T21:21:51Z</dc:date>
    </item>
    <item>
      <title>Re: Macro error?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-error/m-p/537879#M148006</link>
      <description>&lt;P&gt;These are all numeric variables ... so ... following the suggestion given by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    if nmiss(admitdt,dischargedt, /* you type the rest of the variable names */)=0;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Alternatively, you can use &lt;A href="https://documentation.sas.com/?docsetId=lrcon&amp;amp;docsetTarget=p0wphcpsfgx6o7n1sjtqzizp1n39.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_self"&gt;SAS variable lists&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;for example if your variables are consecutive in the data set, then this ought to work:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    if nmiss(of admitdt--rapid)=0;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;By the way, don't you mean&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if admitdt ^=. AND dischargedt^=. &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 23 Feb 2019 02:32:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-error/m-p/537879#M148006</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-02-23T02:32:53Z</dc:date>
    </item>
    <item>
      <title>Re: Macro error?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-error/m-p/537930#M148034</link>
      <description>&lt;P&gt;You will always have to&amp;nbsp; type the variable names once, if only to complete a %LET statement.&amp;nbsp; If this code is working code, and this is the only place you need a list of variables, you could use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;if n(admitdt, dischargedt, stay, hosp, hospdt, dob, sex, disd, antivir, cxr, rapid) &amp;gt; 0;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All the variables must be numeric for this to work.&amp;nbsp; (But they all would need to be numeric for your original code to be valid as well.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, if some variables are character, changes are needed.&amp;nbsp; If the list of variables needs to be used elsewhere in your program, changes are required.&amp;nbsp; If none of those conditions applies, you should be all set.&amp;nbsp; But if changes are needed, you will need to explain more.&lt;/P&gt;</description>
      <pubDate>Sat, 23 Feb 2019 03:26:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-error/m-p/537930#M148034</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-02-23T03:26:52Z</dc:date>
    </item>
    <item>
      <title>Re: Macro error?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-error/m-p/538163#M148127</link>
      <description>&lt;P&gt;1.&amp;nbsp;Invalid Variable name 23hrstay&lt;/P&gt;&lt;P&gt;2. cmiss or nmiss is the best way of doing your code&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please find the bellow approach.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;option source source2 mprint;
%macro runit;

%let vars = admitdt dischargedt v_23hrstay hosp hospdt dob sex antimed rapidRT;

%let v_count=%sysfunc(countw(&amp;amp;vars, ' '));

%put &amp;amp;=v_count;

data want;
	set have;
	if 
	%do i=1 %to &amp;amp;v_count.;
		%sysfunc(scan(&amp;amp;vars,&amp;amp;i)) %str(ne .)
		%if &amp;amp;i ne &amp;amp;v_count %then %str(or);
	%end;;
run;

%mend runit;

%runit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Please let us know if it worked for you.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Feb 2019 02:05:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-error/m-p/538163#M148127</guid>
      <dc:creator>Satish_Parida</dc:creator>
      <dc:date>2019-02-25T02:05:57Z</dc:date>
    </item>
    <item>
      <title>Re: Macro error?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-error/m-p/538330#M148183</link>
      <description>&lt;P&gt;Thank you so much, &lt;A class="lia-link-navigation lia-page-link lia-user-name-link" id="link_58" style="color: rgb(0, 125, 195);" href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138619" target="_self"&gt;&lt;SPAN class="login-bold"&gt;Satish_Parida&lt;/SPAN&gt;&lt;/A&gt;!&amp;nbsp;&amp;nbsp; Your code is awesome!&amp;nbsp; &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Feb 2019 16:37:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-error/m-p/538330#M148183</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2019-02-25T16:37:47Z</dc:date>
    </item>
    <item>
      <title>Re: Macro error?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-error/m-p/538331#M148184</link>
      <description>&lt;P&gt;Thanks for all of the expertise advice.&amp;nbsp; I learn a lot .&lt;/P&gt;</description>
      <pubDate>Mon, 25 Feb 2019 16:38:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-error/m-p/538331#M148184</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2019-02-25T16:38:54Z</dc:date>
    </item>
  </channel>
</rss>

