<?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: SAS macro does not run or run without stopping in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-does-not-run-or-run-without-stopping/m-p/480757#M286637</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/222587"&gt;@AngelaFan&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you for your responses. The code works just fine. It is the macro which works funky.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;********* (redacted). Sorry for the hard word, but there is NO macro logic at all in your macro, so the macro itself CANNOT be the reason.&lt;/P&gt;
&lt;P&gt;Remove the %macro and %mend (and the macro call), set the single parameter as a macro variable, execute the Base SAS code step-by-step, and inspect the log after each single step. Successful macro programming will ALWAYS start with getting working Base SAS code first.&lt;/P&gt;</description>
    <pubDate>Tue, 24 Jul 2018 10:57:01 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2018-07-24T10:57:01Z</dc:date>
    <item>
      <title>SAS macro does not run or run without stopping</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-does-not-run-or-run-without-stopping/m-p/480626#M286624</link>
      <description>&lt;P&gt;I am having an issue with macro function. The SAS code works just fine when not used in the macro function.&amp;nbsp; Attached is the code for the first macro and the second macros is almost the same but with some more programming on a third variable the first macro does not have .&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I run the first macro, it ran most of the time but sometime it does run and the log is just black line of codes.&lt;/P&gt;&lt;P&gt;When I run the second macro (not attached here), it did not run for most of the time, and it works mostly only if I close sas program and rerun the second macro without running the first one. And a lot of time it runs without stopping, which drives me crazy.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would appreciate any help from anyone who had encountered the same problem like me. Thanks a lot.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro Exam(Program);
.....................
%mend Exam;

%Exam(Program=XY);&lt;BR /&gt;%Exam(Program=UW);&lt;BR /&gt;%Exam(Program=ST);&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;%Macro Exam2(Program, Class);&lt;BR /&gt;..................... &lt;BR /&gt;%mend Exam2;&lt;BR /&gt;%Exam2(Program=ABC, Class=D);&lt;BR /&gt;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jul 2018 13:06:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-does-not-run-or-run-without-stopping/m-p/480626#M286624</guid>
      <dc:creator>AngelaFan</dc:creator>
      <dc:date>2018-07-24T13:06:17Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro does not run or run without stopping</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-does-not-run-or-run-without-stopping/m-p/480642#M286625</link>
      <description>&lt;P&gt;Given the size of your code, I don't have time to review&amp;nbsp;it carefully. However, a couple of points that you might want to address:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. You use * comments. DON'T! They often will end up being part of the code, rather than the comment you were trying to insert. Instead use either %* comment OR /* comment */&lt;/P&gt;
&lt;P&gt;2. Your macro appears to rely on some macro variables that are created outside of the macro. I try to include all such variables as parameters to the macro&lt;/P&gt;
&lt;P&gt;3. When testing your macro, if often helps to set: options mprint mlogic symbolgen; Those option settings provide a lot of detail one needs to debug a macro&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jul 2018 21:29:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-does-not-run-or-run-without-stopping/m-p/480642#M286625</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2018-07-23T21:29:24Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro does not run or run without stopping</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-does-not-run-or-run-without-stopping/m-p/480648#M286626</link>
      <description>&lt;P&gt;&lt;EM&gt;I specifically used %mend with the macro name to tell sas please stop the corresponding macro.&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;The word after mend is not useful to&amp;nbsp;SAS, consider it a comment for yourself.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may not like it, but the symptoms you indicate point to something not being closed properly, as you say.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Maybe it's due to some macro variables containing unbalanced quotes, or something similar. Who knows. You have to&amp;nbsp;study the log now.&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jul 2018 22:08:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-does-not-run-or-run-without-stopping/m-p/480648#M286626</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-07-23T22:08:37Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro does not run or run without stopping</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-does-not-run-or-run-without-stopping/m-p/480666#M286627</link>
      <description>&lt;P&gt;Is the purpose of this code to read the second line of a data file for variable names so you can use Proc Import to read data?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If so try something like&lt;/P&gt;
&lt;PRE&gt;data _null_;
   infile "&amp;amp;win5.\&amp;amp;Program._Input.txt";
   file "&amp;amp;win5.\&amp;amp;Program._Input2.txt";
   input;
   If _n_&amp;gt;1 then put _infile_;
run;&lt;/PRE&gt;
&lt;P&gt;and use Proc import to read the _input2.txt version of the file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If these files occur in the same layout(s) you would be better off writing a proper data step to read each layout where you control the variable names, format and informats. If you know what order the variables are then using the option firstobs=3 would read the first line of data.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jul 2018 23:15:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-does-not-run-or-run-without-stopping/m-p/480666#M286627</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-07-23T23:15:32Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro does not run or run without stopping</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-does-not-run-or-run-without-stopping/m-p/480678#M286628</link>
      <description>&lt;P&gt;Thank you Sir. I can work on the comment part, but all the macro variables are specified in the very beginning so that I can use it throughout my code whenever I refer to a macro variable. I also appreciate the debug suggestion. I will give it a try. Thanks,&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jul 2018 00:50:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-does-not-run-or-run-without-stopping/m-p/480678#M286628</guid>
      <dc:creator>AngelaFan</dc:creator>
      <dc:date>2018-07-24T00:50:58Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro does not run or run without stopping</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-does-not-run-or-run-without-stopping/m-p/480679#M286629</link>
      <description>&lt;P&gt;I do not agree with you on that. lol~~~And I check log for every line of code. Thanks for the response.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jul 2018 00:52:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-does-not-run-or-run-without-stopping/m-p/480679#M286629</guid>
      <dc:creator>AngelaFan</dc:creator>
      <dc:date>2018-07-24T00:52:14Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro does not run or run without stopping</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-does-not-run-or-run-without-stopping/m-p/480680#M286630</link>
      <description>&lt;P&gt;When the macro function runs, the data are read in properly. The second line is just all the variable names I want to extract and use later. Thank you for the response.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jul 2018 00:53:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-does-not-run-or-run-without-stopping/m-p/480680#M286630</guid>
      <dc:creator>AngelaFan</dc:creator>
      <dc:date>2018-07-24T00:53:48Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro does not run or run without stopping</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-does-not-run-or-run-without-stopping/m-p/480684#M286631</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/222587"&gt;@AngelaFan&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;The macro you've posted doesn't use any SAS macro logic but it's just a way to call the same code multiple times passing while passing in a different parameter value. That will make it really simple to debug your code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Put lines with %macro, %mend and %exam into comment&lt;/P&gt;
&lt;P&gt;2. Add a %let&amp;nbsp;&lt;SPAN&gt;Program&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;XY&lt;/SPAN&gt;; at the top of your code&lt;/P&gt;
&lt;P&gt;3. Now step through your program, issue one run group after the other from top to bottom and always check if the step returns the expected result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's much easier to debug SAS data step and Proc code than macro code. So get first this bit right before you wrap a macro around.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just&amp;nbsp;some things I've seen in your code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1.&amp;nbsp;I guess you want to use the automatic variable _n_ and not some variable _n&lt;/P&gt;
&lt;PRE&gt;    newname = trim((name))|| "_n";
&lt;/PRE&gt;
&lt;P&gt;2. An IN operator for a character variable requires a comma separated list of values in quotes. That's not what your Select Into will populate into &amp;amp;F1count.&lt;/P&gt;
&lt;PRE&gt;  proc sql noprint;
    select AppID
      into:F1count separated by " "  
    from F1examinees;
  quit;

  ***This is F1 data;
  data F1;
    set Pfile2;
    where NAME in (&amp;amp;F1count.);
  run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jul 2018 01:09:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-does-not-run-or-run-without-stopping/m-p/480684#M286631</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2018-07-24T01:09:00Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro does not run or run without stopping</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-does-not-run-or-run-without-stopping/m-p/480689#M286632</link>
      <description>&lt;P&gt;I made sure the macro function run with substituting variables. When I put it into macro and ran a second macro with almost the same code, it did not run or run sometimes. Very weird. Thank you for your response&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jul 2018 01:40:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-does-not-run-or-run-without-stopping/m-p/480689#M286632</guid>
      <dc:creator>AngelaFan</dc:creator>
      <dc:date>2018-07-24T01:40:36Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro does not run or run without stopping</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-does-not-run-or-run-without-stopping/m-p/480693#M286633</link>
      <description>&lt;P&gt;First place I would look:&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is in VARNAMES1?&amp;nbsp; And what gets written as the value of &amp;amp;COLNAMES?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have an extra variable or two in the incoming data, you can end up with a blank value for COL1.&amp;nbsp; That can throw off the logic of the RENAME list when creating PFILE.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jul 2018 02:27:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-does-not-run-or-run-without-stopping/m-p/480693#M286633</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-07-24T02:27:40Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro does not run or run without stopping</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-does-not-run-or-run-without-stopping/m-p/480698#M286634</link>
      <description>&lt;P&gt;Thank you for your responses. The code works just fine. It is the macro which works funky.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jul 2018 03:13:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-does-not-run-or-run-without-stopping/m-p/480698#M286634</guid>
      <dc:creator>AngelaFan</dc:creator>
      <dc:date>2018-07-24T03:13:22Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro does not run or run without stopping</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-does-not-run-or-run-without-stopping/m-p/480703#M286635</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/222587"&gt;@AngelaFan&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you for your responses. The code works just fine. It is the macro which works funky.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Based on the code you've posted it's almost certainly not the macro as you don't use any macro logic anywhere.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Because the SAS code is wrapped into a macro it can be that issues surface a bit differently - but it's about issues with your other SAS code. ...and for this reason first fix and test the code before wrapping the macro around.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jul 2018 03:47:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-does-not-run-or-run-without-stopping/m-p/480703#M286635</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2018-07-24T03:47:28Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro does not run or run without stopping</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-does-not-run-or-run-without-stopping/m-p/480704#M286636</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;2. An IN operator for a character variable requires a comma separated list of values in quotes. That's not what your Select Into will populate into &amp;amp;F1count.&lt;/P&gt;
&lt;PRE&gt;  proc sql noprint;
    select AppID
      into:F1count separated by " "  
    from F1examinees;
  quit;

  ***This is F1 data;
  data F1;
    set Pfile2;
    where NAME in (&amp;amp;F1count.);
  run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;If the variable NAME used in the WHERE statement is really character then you will need to quote the elements in the list.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select quote(trim(AppID))
  into :F1count separated by " "  
  from F1examinees
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BUT the IN operator is SAS does &lt;STRONG&gt;NOT&lt;/STRONG&gt; require commas between the elements in the list.&amp;nbsp; You can use commas if you want to but in general it will just make the macro variable harder to work with than if you used space as the delimiter.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try it yourself.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jul 2018 03:55:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-does-not-run-or-run-without-stopping/m-p/480704#M286636</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-07-24T03:55:55Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro does not run or run without stopping</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-does-not-run-or-run-without-stopping/m-p/480757#M286637</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/222587"&gt;@AngelaFan&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you for your responses. The code works just fine. It is the macro which works funky.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;********* (redacted). Sorry for the hard word, but there is NO macro logic at all in your macro, so the macro itself CANNOT be the reason.&lt;/P&gt;
&lt;P&gt;Remove the %macro and %mend (and the macro call), set the single parameter as a macro variable, execute the Base SAS code step-by-step, and inspect the log after each single step. Successful macro programming will ALWAYS start with getting working Base SAS code first.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jul 2018 10:57:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-does-not-run-or-run-without-stopping/m-p/480757#M286637</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-07-24T10:57:01Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro does not run or run without stopping</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-does-not-run-or-run-without-stopping/m-p/480764#M286638</link>
      <description>I said clearly. There is nothing wrong with the base code. If my macro is not macro, why do not you show me what is a macro. My sad teacher will be so mad because u said the macro he taught me is not macro at all. &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 24 Jul 2018 11:36:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-does-not-run-or-run-without-stopping/m-p/480764#M286638</guid>
      <dc:creator>AngelaFan</dc:creator>
      <dc:date>2018-07-24T11:36:04Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro does not run or run without stopping</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-does-not-run-or-run-without-stopping/m-p/480765#M286639</link>
      <description>The base code works. Thank you.&lt;BR /&gt;</description>
      <pubDate>Tue, 24 Jul 2018 11:37:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-does-not-run-or-run-without-stopping/m-p/480765#M286639</guid>
      <dc:creator>AngelaFan</dc:creator>
      <dc:date>2018-07-24T11:37:04Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro does not run or run without stopping</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-does-not-run-or-run-without-stopping/m-p/480767#M286640</link>
      <description>&lt;P&gt;Run this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let program=XY;

proc IMPORT datafile="&amp;amp;win5.\&amp;amp;Program._Input.txt" out=PFile 
dbms=dlm replace;
delimiter='09'x;
getnames=YES;
datarow=2; 
run; 

 
data Varnames;
	set PFile(firstobs=1 obs=1);
run;

*Transpose the dataset to get colnames;
proc transpose data=Varnames(obs=1) out=Varnames1;
	var _all_;
run;


data Varnames1;
	set Varnames1;
	if Col1="PBSX-E" THEN Col1="PBSXE";
	if col1="IN.MSQ" THEN col1="IN_MSQ";
    if col1="IN.ZSTD" THEN col1="IN_ZSTD";
	if col1="OUT.MSQ" THEN col1="OUT_MSQ";
    else if col1="OUT.ZSTD" THEN col1="OUT_ZSTD";
run;

*Create macro for each colname;
proc sql noprint;
	select catx('=',_name_,col1)
	into :colnames separated by " " 
	from Varnames1;
quit;

%put &amp;amp;colnames;

*Final data with appriopriate column names added;
data PFile;
	set PFile(firstobs=2 rename=(&amp;amp;colnames));
run;

data PFile1;
set PFile(keep=ENTRY NAME COUNT SCORE MEASURE STATUS MODLSE);
run; 

*convert all variables into numeric; 
proc contents data=PFile1 out=vars(keep=name type) noprint;
data vars;
set vars;
if type=2;
newname = trim((name))|| "_n";

proc sql noprint;
select name,  newname,
       newname || '=' || name 
into :ch_list SEPARATEd by " " , :num_list separated by " " ,
     :rename_list separated by " " 
from vars;
quit;

data PFILE2;
 set PFILE1;
array ch(*) $ &amp;amp;ch_list;
array nu(*) &amp;amp;num_list;
do i=1 to dim(ch);
   nu(i) = input(ch(i),10.);
end;
drop i &amp;amp;ch_list;
rename &amp;amp;rename_list;
run; 


proc import out=F1Examinees datafile="&amp;amp;win9.\&amp;amp;Program._exs.xlsx" dbms=xlsx replace;
getnames=YES;
run;

proc sql noprint;
select AppID
into:F1count separated by " "  
from F1examinees;
quit;

***This is F1 data;
data F1;
set Pfile2;
where NAME in (&amp;amp;F1count.); 
run;

data F1score;
set F1(keep=Name score);
run;

proc means data=F1score mean median std min max;
var score;
output out=F1raw mean=Mean median=Median std=SD min=Min max=Max;
run;

data F1raw;
set F1raw;
form=1;
run;

*Find reliability;
data F1theta;
set F1(keep=Name MEASURE MODLSE);
run;

data F1theta;
set F1theta;
SE_squared=MODLSE*MODLSE;
run;

proc means data=F1theta mean var noprint;
var Measure SE_squared;
output out=F1out var(Measure)= mean(SE_squared)=/autoname;
run;

data F1out1;
set F1out;
form=1;
reliability=(Measure_Var-SE_squared_mean)/ Measure_Var;
run;

data new;
set F1out1;
set F1raw;
run;


data new1;
set new;
SEM=SD*sqrt(1-reliability); 
run;

*drop unnneed variables;
data var;
set new1(keep=_FREQ_ Mean Median SD Min Max Reliability SEM);
run;

data var1;
set var;
N=_FREQ_;
drop _FREQ_;
run;


proc import out=Count datafile= "&amp;amp;win9.\&amp;amp;Program._Count.xlsx" dbms=xlsx replace;
getnames=YES;
run;

data F1_final;
set Count;
if formid = "&amp;amp;Program.001" &amp;amp; score = 0 then NOP= count;
if formid = "&amp;amp;Program.001" &amp;amp; score = 1 then NPT= count;
*Nexcluded=&amp;amp;F1inval.;
run;

data F1_final1;
set F1_final;
set F1_allpt(rename=(count=AllPT));
set var1;
run;

data F1_final2;
retain NOP AllPT NPT N Nexcluded Mean Median SD Min Max Reliability SEM;
set F1_final1;
run;

proc transpose data=F1_final2 out=F1_PSummary;
var _all_;
run;

*Get all the valid form 2 person information;
***This is F2 data;
data F2;
set Pfile2;
if name in (&amp;amp;F1count.) then delete;
run;
 
data F2score;
set F2(keep=Name score);

run;

proc means data=F2score mean median std min max;
var score;
output out=F2raw mean=Mean median=Median std=SD min=Min max=Max;
run;

data F2raw;
set F2raw;
form=2;
run;

*Find reliability;
data F2theta;
set F2(keep=Name MEASURE MODLSE);
run;

data F2theta;
set F2theta;
SE_squared=MODLSE*MODLSE;
run;

proc means data=F2theta mean var noprint;
var Measure SE_squared;
output out=F2out var(Measure)= mean(SE_squared)=/autoname;
run;

data F2out1;
set F2out;
form=2;
reliability=(Measure_Var-SE_squared_mean)/ Measure_Var;
run;

data new;
set F2out1;
set F2raw;
run;


data new1;
set new;
SEM=SD*sqrt(1-reliability); 
run;

*drop unnneed variables;
data var;
set new1(keep=_FREQ_ Mean Median SD Min Max Reliability SEM);
run;

data var1;
set var;
N=_FREQ_;
drop _FREQ_;
run;

data F2_final;
NOP= &amp;amp;F2_OPN.;
NPT= &amp;amp;F2_PTN.;
Nexcluded=&amp;amp;F2inval.;
run;

data F2_final1;
set F2_final;
set F2_allpt(rename=(count=AllPT));
set var1;
run;

data F2_final2;
retain NOP AllPT NPT N Nexcluded Mean Median SD Min Max Reliability SEM;
set F2_final1;
run;

proc transpose data=F2_final2 out=F2_PSummary;
var _all_;
run;


************************************************************************;
****************************Final Output***************************************; 
data FinalF1F2;
set F1_PSummary F2_PSummary;
run;

proc export data=FinalF1F2 outfile="&amp;amp;win9.\&amp;amp;Program._Candidate.xlsx" dbms=xlsx replace;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;step-by-step and inspect the log. If it works, your macro will also work, because it does &lt;FONT size="4"&gt;&lt;STRONG&gt;NOTHING &lt;/STRONG&gt;&lt;FONT size="2"&gt;but replacing &amp;amp;program with XY.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="4"&gt;&lt;FONT size="2"&gt;If there's still any problem, post the log &lt;EM&gt;as is&lt;/EM&gt; into a {i} window.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jul 2018 11:41:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-does-not-run-or-run-without-stopping/m-p/480767#M286640</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-07-24T11:41:51Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro does not run or run without stopping</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-does-not-run-or-run-without-stopping/m-p/480769#M286641</link>
      <description>There is problem with the code. Thank you. I need the code to run many programs. That’s why I made the code chunk a macro. Thank you.&lt;BR /&gt;</description>
      <pubDate>Tue, 24 Jul 2018 11:44:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-does-not-run-or-run-without-stopping/m-p/480769#M286641</guid>
      <dc:creator>AngelaFan</dc:creator>
      <dc:date>2018-07-24T11:44:04Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro does not run or run without stopping</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-does-not-run-or-run-without-stopping/m-p/480770#M286642</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/222587"&gt;@AngelaFan&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;There is problem with the code. Thank you. I need the code to run many programs. That’s why I made the code chunk a macro. Thank you.&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Surprise, surprise.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jul 2018 11:44:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-does-not-run-or-run-without-stopping/m-p/480770#M286642</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-07-24T11:44:52Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro does not run or run without stopping</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-does-not-run-or-run-without-stopping/m-p/480866#M286643</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/222587"&gt;@AngelaFan&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;The base code works. Thank you.&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;What code?&lt;/P&gt;
&lt;P&gt;You have removed all of the actual code so now no one can reference it.&lt;/P&gt;
&lt;P&gt;Without code how can anyone suggest corrections?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jul 2018 17:38:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-does-not-run-or-run-without-stopping/m-p/480866#M286643</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-07-24T17:38:02Z</dc:date>
    </item>
  </channel>
</rss>

