<?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: Creating a XPT macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-XPT-macro/m-p/766630#M242985</link>
    <description>&lt;P&gt;Hi, I wantedly removed my personal folder path name, incase if someone wants to try they can input the parameters.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to run it on your pc pplease provide the path and see if it works.&lt;/P&gt;</description>
    <pubDate>Wed, 08 Sep 2021 16:02:26 GMT</pubDate>
    <dc:creator>bharath86</dc:creator>
    <dc:date>2021-09-08T16:02:26Z</dc:date>
    <item>
      <title>Creating a XPT macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-XPT-macro/m-p/766625#M242981</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to create a macro for converting sas7bdat files to XPT's in a batch. Please find the attached code.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please help me debug the code. it doesnt produce the output and no warnings in log.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Macro for converting SAS7bdat to xpts */
%macro xpmac(sasfloc=,ioutploc=,);

/*To get list of files in directory*/
data tdata;
	length fname $300.;
	rc=filename("filrf","&amp;amp;sasfloc");
	did=dopen("filrf");
	memcount=dnum(did);
	if memcount&amp;gt;0 then do;
	do i=1 to memcount;
	fname=upcase(dread(did,i));
	if index(trim(left(upcase(reverse(fname)))),'TDB7SAS.')=1 then output;
	end;
end;
else stop;
rc=dclose(did);
run;

%let sasfcount=0; 

/*Assign in macro variable for naming the sas7bdat file*/
data new;
	set tdata end=last;
	call symput('sasbfile'||left(_n_),trim(left(fname)));
	if last then call symput('sasfcount',left(_n_));
run;

/*library for output dataset location;*/
libname libout xport "&amp;amp;ioutploc";
/*Do Loop for each sas7bdat file;*/
%do lindx=1 %to &amp;amp;sasfcount; 

/*Assign file reference to the sas7bdat file*/
filename ftemp "&amp;amp;sasfloc\&amp;amp;&amp;amp;sasbfile&amp;amp;lindx";

/*Reading the first line of the sas7bdat file*/
data _null_;
	length firstline $15.;
	infile ftemp obs=1;
	input firstline;
	if index(upcase(firstline),'HEADER')&amp;gt;0 then call symput('lxpttype','COPY');
run;

%if &amp;amp;lxpttype=COPY %then %do;

	
	libname libin "&amp;amp;sasfloc\&amp;amp;&amp;amp;sasbfile&amp;amp;lindx";

	/*For converting xpt to datasets*/
	proc sql noprint;
	  create table _tmembers as select memname, "&amp;amp;&amp;amp;sasbfile&amp;amp;lindx" as source length 200 from dictionary.tables where libname='LIBIN';
	  (select memname from dictionary.tables where libname='LIBIN');
	quit;
	proc copy in=libin out=libout memtype=data; 
	run;
	
	%end;
%end;

%mend xpmac;

%xpmac(sasfloc=,ioutploc=)
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thank you&lt;/P&gt;
&lt;P&gt;Bharath&lt;/P&gt;</description>
      <pubDate>Wed, 08 Sep 2021 15:37:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-XPT-macro/m-p/766625#M242981</guid>
      <dc:creator>bharath86</dc:creator>
      <dc:date>2021-09-08T15:37:35Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a XPT macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-XPT-macro/m-p/766629#M242984</link>
      <description>Well you called the macro without any parameters so it definitely won't work. &lt;BR /&gt;&lt;BR /&gt;%xpmac(sasfloc=,ioutploc=)&lt;BR /&gt;&lt;BR /&gt;What happens if you add the macro debugging options and run it with file paths?&lt;BR /&gt;&lt;BR /&gt;options mprint symbolgen;&lt;BR /&gt;&lt;BR /&gt;*rest of your code....</description>
      <pubDate>Wed, 08 Sep 2021 15:57:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-XPT-macro/m-p/766629#M242984</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-09-08T15:57:39Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a XPT macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-XPT-macro/m-p/766630#M242985</link>
      <description>&lt;P&gt;Hi, I wantedly removed my personal folder path name, incase if someone wants to try they can input the parameters.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to run it on your pc pplease provide the path and see if it works.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Sep 2021 16:02:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-XPT-macro/m-p/766630#M242985</guid>
      <dc:creator>bharath86</dc:creator>
      <dc:date>2021-09-08T16:02:26Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a XPT macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-XPT-macro/m-p/766634#M242986</link>
      <description>&lt;P&gt;So you want to convert SAS7BDAT files into XPORT files?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You don't need to hunt for SAS7BDAT files.&amp;nbsp; Let SAS do that.&amp;nbsp; Just point a libref at the directory.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro xpmac(sasfloc=,ioutploc=);

libname inlib "&amp;amp;sasfloc";
libname outlib xport "&amp;amp;ioutploc";
proc copy inlib=inlib outlib=outlib;
run;

%mend;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So then just call the macro with an source directory and a target filename:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%xpmac
(sasfloc=c:\mydata\lib1
,ioutploc=c:\mydata\lib1.xpt
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also:&lt;/P&gt;
&lt;P&gt;You have a step that appears to be trying to determine something from reading the beginning of the SAS7BDAT file.&amp;nbsp; That is something you would need to do if you were trying to go the other way.&amp;nbsp; The XPT file extension has no real intrinsic meaning. People can use if for any type of file they want.&amp;nbsp; So they could create an XPORT file using the the XPORT engine and call it a .xpt file. Or they could use PROC CPORT to create the file instead.&amp;nbsp; Or they could use the SAS supplied %LOC2XPT() macro to create an XPORT file using the extended V8/V9 definition that the XPORT engine cannot read or write.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The corresponding test you might want to do is to check if the SAS datasets in the directory have any features that would make them incompatible with the XPORT engine.&amp;nbsp; Things to check:&amp;nbsp; Name longer than 8 bytes. Length larger than 200 bytes. FORMAT name or INFORMAT name longer than 8 bytes.&amp;nbsp; Label or Memlabel longer than 40 bytes.&amp;nbsp; Non standard member name or variable name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Sep 2021 16:41:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-XPT-macro/m-p/766634#M242986</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-09-08T16:41:21Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a XPT macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-XPT-macro/m-p/766642#M242987</link>
      <description>&lt;P&gt;what if I try to simplyfy the complete code this way.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This still doesnt give me the output, i have checked all the parameters as you mentioned but it still doesnt produce the XPT file and log doesnt warn anything.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;can you please try this code and see if it works for you.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%Macro ds();
Libname Raw_sets "D:\Data";
Libname Raw_xpt xport "D:\Data\New folder\&amp;amp;ds..xpt";

proc copy in=Raw_sets out=Raw_xpt;
select &amp;amp;ds;
run;

%Mend;

%ds(ae);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 08 Sep 2021 16:58:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-XPT-macro/m-p/766642#M242987</guid>
      <dc:creator>bharath86</dc:creator>
      <dc:date>2021-09-08T16:58:06Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a XPT macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-XPT-macro/m-p/766657#M242988</link>
      <description>&lt;P&gt;And what does the SAS log tell you is wrong? Did you turn on the MPRINT option so you can see the SAS code that the macro generated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Where did you define the macro variable DS your code is referencing?&lt;/P&gt;
&lt;P&gt;Why are you trying to pass a parameter value to macro that does not have any parameters defined?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro ds(ds);
libname raw_sets "D:\Data";

%if not %sysfunc(exist(raw_sets.&amp;amp;ds)) %then %do;
  %put ERROR: Dataset RAW_SETS.&amp;amp;ds does not exist ;
%end;
%else %do;

libname raw_xpt xport "D:\Data\New folder\&amp;amp;ds..xpt";

proc copy in=Raw_sets out=Raw_xpt;
select &amp;amp;ds;
run;
%end;
%mend ds;

%ds(ae);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 08 Sep 2021 17:32:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-XPT-macro/m-p/766657#M242988</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-09-08T17:32:35Z</dc:date>
    </item>
  </channel>
</rss>

