<?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 to read XPT files in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-to-read-XPT-files/m-p/750591#M38993</link>
    <description>&lt;P&gt;No need macro .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
/*************一个XPT文件 转成 一个SAS数据集************/
/* path to address xpt file*/
%let path_in= D:\XiaKeShan\my_code\数据管理\转XPT文件\XPT  ;
/* path to store sas dataset*/
%let path_out= D:\XiaKeShan\my_code\数据管理\转XPT文件\SAS  ;


/*transform a xpt file into a sas dataaset*/
libname out v9 "&amp;amp;path_out";
data _null_;
rc=filename('x',"&amp;amp;path_in");
did=dopen('x');
do i=1 to dnum(did);
  memname=dread(did,i);
call execute(cat("libname tranfile xport '&amp;amp;path_in\",strip(memname),"';proc copy in=tranfile out=out ;run;"));
end;

run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 26 Jun 2021 10:40:54 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2021-06-26T10:40:54Z</dc:date>
    <item>
      <title>Macro to read XPT files</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-to-read-XPT-files/m-p/750560#M38983</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am new at using macros. I was given a macro to convert XPT files to a SAS dataset. Here is the code.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro drive(dir,ext,out);                                                                                                                                                                                                                                                       
  %let filrf=mydir;                                                                                                                                                                                                                                                  
  /* Assigns the fileref of mydir to the directory and opens the directory */                                                                    
  %let rc=%sysfunc(filename(filrf,&amp;amp;dir));                                                                                                
  %let did=%sysfunc(dopen(&amp;amp;filrf));                                                                                                      
  /* Returns the number of members in the directory */                                                                   
  %let memcnt=%sysfunc(dnum(&amp;amp;did));                                                                                                                                                                                                                                       
   /* Loops through entire directory */                                                                                                  
   %do i = 1 %to &amp;amp;memcnt;                                                                                                                
         /* Returns the extension from each file */                                                                                                                                    
     %let name=%qscan(%qsysfunc(dread(&amp;amp;did,&amp;amp;i)),-1,.);                                                                                                                                                                                                  
     /* Checks to see if file contains an extension */                                                                                     
     %if %qupcase(%qsysfunc(dread(&amp;amp;did,&amp;amp;i))) ne %qupcase(&amp;amp;ext) %then %do;                                                                                                                                                                                               
     /* Checks to see if the extension matches the parameter value */                                                                      
     /* If condition is true, submit PROC COPY statement  */                                                                      
     %if (%superq(ext) ne and %qupcase(&amp;amp;name) = %qupcase(&amp;amp;ext)) or                                                                       
         (%superq(ext) = and %superq(name) ne) %then %do;                                                           
     	    libname old xport "&amp;amp;dir.\%qsysfunc(dread(&amp;amp;did,&amp;amp;i))"; 
		libname new "&amp;amp;out";
		proc copy in=old out=new;
		run;
     %end;                                                                                                                               
   %end; 
  %end; 
                                                                                                                                        
  /* Close the directory */                                                                                                            
  %let rc=%sysfunc(dclose(&amp;amp;did));                                                                                                        
/* END MACRO */                                                                                                                                           
%mend drive;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;When I run the following code&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%drive('\appdata\sasusers\JLANG\NHANES data', 'XPT', '\appdata\sasusers\JLANG\NHANES data\DATA')&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I receive the following error.&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was:&lt;BR /&gt;&amp;amp;memcnt&lt;BR /&gt;ERROR: The %TO value of the %DO I loop is invalid.&lt;BR /&gt;ERROR: The macro DRIVE will stop executing.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;The name of the file that Im trying to convert is DEMO_F.XPT&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please let me know what im doing wrong here!&lt;/P&gt;&lt;P&gt;Thanks for your help &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 26 Jun 2021 02:17:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-to-read-XPT-files/m-p/750560#M38983</guid>
      <dc:creator>Justin_Lang</dc:creator>
      <dc:date>2021-06-26T02:17:12Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to read XPT files</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-to-read-XPT-files/m-p/750562#M38984</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/283581"&gt;@Justin_Lang&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Think of SAS macros as text generators. Your macro is generating SAS syntax (libnames/proc copy) which SAS then executes once the macro has done its job generating the syntax.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Using a macro should be simple if also given the docu how parameter passing needs to look like. It's likely not the ideal macro for a beginner to also get into understanding the macro syntax.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The macro parameters are:&lt;/P&gt;
&lt;P&gt;- dir: The source directory the macro will inspect (all sub-directories included!)&lt;/P&gt;
&lt;P&gt;- ext: The file extension the macro will look for&lt;/P&gt;
&lt;P&gt;- out: The target directory .xpt files will get copied to as .sas7bdat files&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The macro will actually only work for .xpt files so there shouldn't be a parameter ext but this should better be hard-coded in the macro (or macro logic changed to also deal with other extensions).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The macro is based on SAS Sample macro %drive() documented &lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/n0ctmldxf23ixtn1kqsoh5bsgmg8.htm" target="_self"&gt;here&lt;/A&gt;. If you want to understand the macro logic start with the docu and once you've got that look into the version you've have to understand the amendments.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And to answer your question: Pass the parameters without quoting as below:&lt;/P&gt;
&lt;PRE&gt;%drive(\appdata\sasusers\JLANG\NHANES data, XPT, \appdata\sasusers\JLANG\NHANES data\DATA)&lt;/PRE&gt;
&lt;P&gt;...and on 2nd thought: The backslashes indicate a Windows environment but if so then you would either need a drive letter like &lt;STRONG&gt;d:&lt;/STRONG&gt;\appdata\.... or it's a unc path which then should look like &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;\\&lt;/STRONG&gt;&lt;/FONT&gt;apdata\...&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 26 Jun 2021 04:59:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-to-read-XPT-files/m-p/750562#M38984</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-06-26T04:59:07Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to read XPT files</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-to-read-XPT-files/m-p/750566#M38985</link>
      <description>&lt;P&gt;In addition to what&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;said, this looks like a Windows environment; is that correct?&amp;nbsp; Typically, I see a drive designation preceding the path.&amp;nbsp; Something like:&amp;nbsp; &lt;STRONG&gt;C:\&lt;/STRONG&gt;Windows\Containers although maybe \appdata is correct in your situation.&amp;nbsp; Take the single quotes out as&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;suggests, and that may be all that needs to be done.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's probably OK, but you do realize that there are embedded blanks in the path, yes?&amp;nbsp; That isn't necessarily invalid, but I would check that.&amp;nbsp; It could be an underscore.&amp;nbsp; The dir macro variable has to be correct in order for the memcnt macro variable to be correct.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jimbarbour_0-1624681007038.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/60772i1A1B9D6B73CE6A9D/image-size/large?v=v2&amp;amp;px=999" role="button" title="jimbarbour_0-1624681007038.png" alt="jimbarbour_0-1624681007038.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As far as the macro itself is concerned, you've got an invalid memcnt.&amp;nbsp; If the dir variable is invalid as I suspect it is, then&amp;nbsp;%let rc=%sysfunc(filename(filrf,&amp;amp;dir)); will return a non-zero return code indicating an error.&amp;nbsp; Then, the dopen() in the next statement will not work as it tries to assign a directory ID.&amp;nbsp; Then, when the next statement executes,&amp;nbsp;%let memcnt=%sysfunc(dnum(&amp;amp;did)); does not return a valid numeric count because it requires a valid directory ID.&amp;nbsp; Lastly,&amp;nbsp;%do i = 1 %to &amp;amp;memcnt; is failing because memcnt is not a number.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you fix the directory, all of this may be resolved. If it is not resolved, then we'll have to do some debugging.&amp;nbsp; We'll probably want to put&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%PUT&amp;nbsp; NOTE:&amp;nbsp; &amp;amp;=rc after each %LET rc statement so the return codes will be written to the log.&amp;nbsp; Knowing the return codes should go a long way towards debugging the macro.&amp;nbsp; But it may be that all we need is to fix the dir variable, so let's try that first.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm also wondering if this statement:&amp;nbsp;&amp;nbsp;%let rc=%sysfunc(filename(filrf,&amp;amp;dir));&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;really should have an ampersand in front of filrf, like this:&amp;nbsp;&amp;nbsp; %let rc=%sysfunc(filename(&lt;FONT size="5"&gt;&lt;STRONG&gt;&amp;amp;&lt;/STRONG&gt;&lt;/FONT&gt;filrf,&amp;amp;dir));&lt;/P&gt;
&lt;P&gt;since filrf is a macrovariable, but, again, let's try fixing dir first and see where that takes us.&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro drive(dir,ext,out);                                                                                                                                                                                                                                                       
  %let filrf=mydir;                                                                                                                                                                                                                                                  
  /* Assigns the fileref of mydir to the directory and opens the directory */                                                                    
  %let rc=%sysfunc(filename(filrf,&amp;amp;dir));                                                                                                
  %let did=%sysfunc(dopen(&amp;amp;filrf));                                                                                                      
  /* Returns the number of members in the directory */                                                                   
  %let memcnt=%sysfunc(dnum(&amp;amp;did));                                                                                                                                                                                                                                       
   /* Loops through entire directory */                                                                                                  
   %do i = 1 %to &amp;amp;memcnt;       &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Sat, 26 Jun 2021 04:39:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-to-read-XPT-files/m-p/750566#M38985</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2021-06-26T04:39:37Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to read XPT files</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-to-read-XPT-files/m-p/750567#M38986</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/37107"&gt;@jimbarbour&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Actually tested the macro in a Windows environment and the blank in the folder name is allowed. Once fully qualified valid paths get used and none of the parameters is in quotes the macro works.&lt;/P&gt;</description>
      <pubDate>Sat, 26 Jun 2021 04:42:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-to-read-XPT-files/m-p/750567#M38986</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-06-26T04:42:15Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to read XPT files</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-to-read-XPT-files/m-p/750568#M38987</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;OK, good.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm still a little surprised that&amp;nbsp;&lt;/P&gt;
&lt;PRE class="language-sas"&gt;&lt;CODE&gt;%let rc=%sysfunc(filename(filrf,&amp;amp;dir));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;doesn't need an ampersand preceding the variable filrf, but if it works, I can't argue with that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Sat, 26 Jun 2021 04:45:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-to-read-XPT-files/m-p/750568#M38987</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2021-06-26T04:45:52Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to read XPT files</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-to-read-XPT-files/m-p/750571#M38988</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/37107"&gt;@jimbarbour&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;OK, good.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm still a little surprised that&amp;nbsp;&lt;/P&gt;
&lt;PRE class="language-sas"&gt;&lt;CODE&gt;%let rc=%sysfunc(filename(filrf,&amp;amp;dir));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;doesn't need an ampersand preceding the variable filrf, but if it works, I can't argue with that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/37107"&gt;@jimbarbour&lt;/a&gt;&amp;nbsp;That's how SAS implemented the syntax.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_1-1624683394060.png" style="width: 996px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/60774iDFC62D3592B66B11/image-dimensions/996x92?v=v2" width="996" height="92" role="button" title="Patrick_1-1624683394060.png" alt="Patrick_1-1624683394060.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/n15scht124hr4nn1g296cqg2kqfa.htm" target="_blank"&gt;https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/n15scht124hr4nn1g296cqg2kqfa.htm&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 26 Jun 2021 04:57:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-to-read-XPT-files/m-p/750571#M38988</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-06-26T04:57:28Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to read XPT files</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-to-read-XPT-files/m-p/750572#M38989</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Interesting.&amp;nbsp; I had wondered if it were context sensitive.&amp;nbsp; It's nice to have confirmation.&amp;nbsp; Thank you for that.&lt;/P&gt;
&lt;P&gt;&lt;STRIKE&gt;Even more interesting:&amp;nbsp; It works equally well with an ampersand in front, i.e. &lt;STRONG&gt;&amp;amp;&lt;/STRONG&gt;filrf.&lt;/STRIKE&gt;&amp;nbsp;&amp;nbsp;&lt;STRONG&gt;Edit&lt;/STRONG&gt;: Actually, as&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;points out, it does not work if the var name is preceded by an ampersand.&amp;nbsp; Thank you to Patrick for catching that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I couldn't get it to work with just \appdata alone.&amp;nbsp; I had to precede \appdata with a drive designation and path.&amp;nbsp; I'm not sure if that's some kind of local environmental setting or due to the fact that I'm on Win Server 2016 (as opposed to Win 10 or some other flavor of Windows).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Sat, 26 Jun 2021 15:22:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-to-read-XPT-files/m-p/750572#M38989</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2021-06-26T15:22:45Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to read XPT files</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-to-read-XPT-files/m-p/750580#M38990</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/37107"&gt;@jimbarbour&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"&lt;EM&gt;It works equally well with an ampersand in front, i.e. &lt;STRONG&gt;&amp;amp;&lt;/STRONG&gt;filrf.&lt;/EM&gt;"&lt;/P&gt;
&lt;P&gt;Only because you've made the change after already running without the ampersand in the same SAS session. Do this in a fresh new session and it won't work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"&lt;EM&gt;I had to precede \appdata with a drive designation&lt;/EM&gt;"&lt;/P&gt;
&lt;P&gt;I've already added such a comment to my initial answer. Looks like besides of the quoting the path the op uses isn't valid in a Windows environment.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 26 Jun 2021 06:01:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-to-read-XPT-files/m-p/750580#M38990</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-06-26T06:01:14Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to read XPT files</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-to-read-XPT-files/m-p/750582#M38991</link>
      <description>&lt;P&gt;Both the FILENAME and LIBNAME functions have a side effect on the first argument (if the variable is empty, a random value is created and stored in the variable), which is therefore a "call by reference" and not a "call by value". In C, you would use a pointer (&amp;amp;variable) instead of just the variable name.&lt;/P&gt;
&lt;P&gt;In a data step, the data step compiler handles that (by converting a literal to a variable under the hood), but if the functions are used in a macro, only a macro variable&amp;nbsp;&lt;EM&gt;name&lt;/EM&gt; must be supplied, not the contents (which you would get when &amp;amp;name is resolved).&lt;/P&gt;
&lt;P&gt;The&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/lefunctionsref/n15scht124hr4nn1g296cqg2kqfa.htm" target="_blank" rel="noopener"&gt;documentation&lt;/A&gt;&amp;nbsp;states this explicitly:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;In a macro (for example, in the %SYSFUNC function),&amp;nbsp;&lt;/SPAN&gt;&lt;EM class="xisDoc-userSuppliedValue"&gt;fileref&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;is the name of a macro variable (without an ampersand) whose value contains the fileref to assign to the external file.&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Sat, 26 Jun 2021 06:52:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-to-read-XPT-files/m-p/750582#M38991</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-06-26T06:52:38Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to read XPT files</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-to-read-XPT-files/m-p/750583#M38992</link>
      <description>&lt;P&gt;If macro variable filrf contains a string which can be used as a valid macro variable name, then &lt;EM&gt;that&lt;/EM&gt; macro variable will be created and receive the randomly generated file reference.&lt;/P&gt;</description>
      <pubDate>Sat, 26 Jun 2021 06:56:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-to-read-XPT-files/m-p/750583#M38992</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-06-26T06:56:32Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to read XPT files</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-to-read-XPT-files/m-p/750591#M38993</link>
      <description>&lt;P&gt;No need macro .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
/*************一个XPT文件 转成 一个SAS数据集************/
/* path to address xpt file*/
%let path_in= D:\XiaKeShan\my_code\数据管理\转XPT文件\XPT  ;
/* path to store sas dataset*/
%let path_out= D:\XiaKeShan\my_code\数据管理\转XPT文件\SAS  ;


/*transform a xpt file into a sas dataaset*/
libname out v9 "&amp;amp;path_out";
data _null_;
rc=filename('x',"&amp;amp;path_in");
did=dopen('x');
do i=1 to dnum(did);
  memname=dread(did,i);
call execute(cat("libname tranfile xport '&amp;amp;path_in\",strip(memname),"';proc copy in=tranfile out=out ;run;"));
end;

run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 26 Jun 2021 10:40:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-to-read-XPT-files/m-p/750591#M38993</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-06-26T10:40:54Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to read XPT files</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-to-read-XPT-files/m-p/750603#M38994</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;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;"&lt;EM&gt;It works equally well with an ampersand in front, i.e. &lt;STRONG&gt;&amp;amp;&lt;/STRONG&gt;filrf.&lt;/EM&gt;"&lt;/P&gt;
&lt;P&gt;Only because you've made the change after already running without the ampersand in the same SAS session. Do this in a fresh new session and it won't work.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Ah.&amp;nbsp; You're quite right.&amp;nbsp; How could it be otherwise?&amp;nbsp; If one puts the ampersand in front, then SAS will look for a macro variable with the name of whatever &amp;amp;filrf resolves to.&amp;nbsp; I have put a strike through in my earlier comment.&amp;nbsp; Thank you for pointing that out.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Sat, 26 Jun 2021 15:20:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-to-read-XPT-files/m-p/750603#M38994</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2021-06-26T15:20:41Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to read XPT files</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-to-read-XPT-files/m-p/750607#M38995</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;&amp;amp;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/37107"&gt;@jimbarbour&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Im still running into the same issues. I added the D : and tried the // for my directory. I also tried moving the directory to my personal C:. The problem, i believe, is that my SAS program is on a secure network. If I run the following code I am able to read the XPT file into a SAS format.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;LIBNAME IN XPORT '/appdata/sasusers/JLANG/NHANES_data/DEMO_F.XPT';
LIBNAME OUT '/appdata/sasusers/JLANG/NHANES_data/DATA';

proc copy inlib=IN outlib=out;
	run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This code works perfectly. It may seem odd, but that is the call for the directory on our network. We don't need to add the D : or the //.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just a reminder, the error that I receive is the following&lt;/P&gt;&lt;PRE&gt;ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was: 
       &amp;amp;memcnt 
ERROR: The %TO value of the %DO I loop is invalid.
ERROR: The macro DRIVE will stop executing.&lt;/PRE&gt;&lt;P&gt;The macro that I am trying to use would read multiple XPT files into SAS datasets at the same time.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 26 Jun 2021 16:40:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-to-read-XPT-files/m-p/750607#M38995</guid>
      <dc:creator>Justin_Lang</dc:creator>
      <dc:date>2021-06-26T16:40:22Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to read XPT files</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-to-read-XPT-files/m-p/750608#M38996</link>
      <description>&lt;P&gt;So you should call the macro as&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%drive(/appdata/sasusers/JLANG/NHANES_data,XPT,/appdata/sasusers/JLANG/NHANES_data/DATA)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and change the backslash in the LIBNAME statement to a slash. Set&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;before calling the macro, and post the log if it does not work.&lt;/P&gt;</description>
      <pubDate>Sat, 26 Jun 2021 17:05:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-to-read-XPT-files/m-p/750608#M38996</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-06-26T17:05:58Z</dc:date>
    </item>
  </channel>
</rss>

