<?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 Use macro to create txt file in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Use-macro-to-create-txt-file/m-p/215830#M39823</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a big SAS dataset that has 5m records with 160 variables. I want to create a txt file and then create a zip file of it so I can send to others.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is what I did:&lt;/P&gt;&lt;P&gt;1. Created a macro variable for txt file header called &amp;amp;flat_head. Here is how it look like:&amp;nbsp; ID|F_name|L_name|Age|DOB|Zip_code|City|........&lt;/P&gt;&lt;P&gt;2. Created a macro variable &amp;amp;putvar for put step: ID F_name L_name Age DOB Zip_code City|&lt;/P&gt;&lt;P&gt;3. Created a txt file using these two macro variables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, I'm not sure which step I did wrong. program did not work.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any suggestions on this?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you in advance.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc contents data = file noprint&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; out = test(keep=name rename=(name=varname));&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Proc sql noprint;&lt;/P&gt;&lt;P&gt;&amp;nbsp; select varname into: Flat_head separated by '|'&lt;/P&gt;&lt;P&gt;&amp;nbsp; from test;&lt;/P&gt;&lt;P&gt;%put flat_head=&amp;amp;flat_head.;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data test2;&lt;/P&gt;&lt;P&gt;&amp;nbsp; Set test END=LAST;&lt;/P&gt;&lt;P&gt;&amp;nbsp; Length putvar $1000;&lt;/P&gt;&lt;P&gt;&amp;nbsp; IF _N_ EQ 1 Then&amp;nbsp; putvar='';&lt;/P&gt;&lt;P&gt;&amp;nbsp; putvar=Trim(putvar)||' '||Trim(varname);&lt;/P&gt;&lt;P&gt;&amp;nbsp; Retain putvar;&lt;/P&gt;&lt;P&gt;&amp;nbsp; IF LAST Then Call Symput('putvar', Trim(putvar));&lt;/P&gt;&lt;P&gt;Run;&lt;/P&gt;&lt;P&gt;%Put putvar=&amp;amp;putvar.;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data _NULL_;&lt;/P&gt;&lt;P&gt;&amp;nbsp; SET file END=EOF;&lt;/P&gt;&lt;P&gt;&amp;nbsp; FILE FLATOUT&amp;nbsp; DELIMITER='|' DSD;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; IF _N_=1 THEN PUT "&amp;amp;Flat_head.";&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; PUT &amp;amp;putvar.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; IF EOF THEN PUT "TOTAL NUMBER OF RECORDS = " _N_;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 16 May 2015 03:15:02 GMT</pubDate>
    <dc:creator>Belle</dc:creator>
    <dc:date>2015-05-16T03:15:02Z</dc:date>
    <item>
      <title>Use macro to create txt file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-macro-to-create-txt-file/m-p/215830#M39823</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a big SAS dataset that has 5m records with 160 variables. I want to create a txt file and then create a zip file of it so I can send to others.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is what I did:&lt;/P&gt;&lt;P&gt;1. Created a macro variable for txt file header called &amp;amp;flat_head. Here is how it look like:&amp;nbsp; ID|F_name|L_name|Age|DOB|Zip_code|City|........&lt;/P&gt;&lt;P&gt;2. Created a macro variable &amp;amp;putvar for put step: ID F_name L_name Age DOB Zip_code City|&lt;/P&gt;&lt;P&gt;3. Created a txt file using these two macro variables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, I'm not sure which step I did wrong. program did not work.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any suggestions on this?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you in advance.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc contents data = file noprint&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; out = test(keep=name rename=(name=varname));&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Proc sql noprint;&lt;/P&gt;&lt;P&gt;&amp;nbsp; select varname into: Flat_head separated by '|'&lt;/P&gt;&lt;P&gt;&amp;nbsp; from test;&lt;/P&gt;&lt;P&gt;%put flat_head=&amp;amp;flat_head.;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data test2;&lt;/P&gt;&lt;P&gt;&amp;nbsp; Set test END=LAST;&lt;/P&gt;&lt;P&gt;&amp;nbsp; Length putvar $1000;&lt;/P&gt;&lt;P&gt;&amp;nbsp; IF _N_ EQ 1 Then&amp;nbsp; putvar='';&lt;/P&gt;&lt;P&gt;&amp;nbsp; putvar=Trim(putvar)||' '||Trim(varname);&lt;/P&gt;&lt;P&gt;&amp;nbsp; Retain putvar;&lt;/P&gt;&lt;P&gt;&amp;nbsp; IF LAST Then Call Symput('putvar', Trim(putvar));&lt;/P&gt;&lt;P&gt;Run;&lt;/P&gt;&lt;P&gt;%Put putvar=&amp;amp;putvar.;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data _NULL_;&lt;/P&gt;&lt;P&gt;&amp;nbsp; SET file END=EOF;&lt;/P&gt;&lt;P&gt;&amp;nbsp; FILE FLATOUT&amp;nbsp; DELIMITER='|' DSD;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; IF _N_=1 THEN PUT "&amp;amp;Flat_head.";&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; PUT &amp;amp;putvar.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; IF EOF THEN PUT "TOTAL NUMBER OF RECORDS = " _N_;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 16 May 2015 03:15:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-macro-to-create-txt-file/m-p/215830#M39823</guid>
      <dc:creator>Belle</dc:creator>
      <dc:date>2015-05-16T03:15:02Z</dc:date>
    </item>
    <item>
      <title>Re: Use macro to create txt file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-macro-to-create-txt-file/m-p/215831#M39824</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Where did you define flatout and there is no quit for your sql statement. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, why the data step for the second macro variable not another sql step?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;proc contents data = file noprint&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; out = test(keep=name rename=(name=varname));&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;Proc sql noprint;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&amp;nbsp; select varname into: Flat_head separated by '|'&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&amp;nbsp; from test;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&amp;nbsp; select varname into: putvar separated by " "&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;from test;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;quit;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;%put flat_head=&amp;amp;flat_head.;&amp;nbsp; &lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;%put put_var=&amp;amp;put_var.;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;data _NULL_;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&amp;nbsp; SET file END=EOF;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&amp;nbsp; FILE 'C:\temp\test.txt'&amp;nbsp; DELIMITER='|' DSD;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&amp;nbsp; IF _N_=1 THEN PUT "&amp;amp;Flat_head.";&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&amp;nbsp; PUT &amp;amp;putvar.;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&amp;nbsp; IF EOF THEN PUT "TOTAL NUMBER OF RECORDS = " _N_;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;RUN;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 16 May 2015 04:35:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-macro-to-create-txt-file/m-p/215831#M39824</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-05-16T04:35:46Z</dc:date>
    </item>
    <item>
      <title>Re: Use macro to create txt file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-macro-to-create-txt-file/m-p/215832#M39825</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Reeza, It works now. &lt;SPAN class="j-post-author "&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 16 May 2015 05:44:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-macro-to-create-txt-file/m-p/215832#M39825</guid>
      <dc:creator>Belle</dc:creator>
      <dc:date>2015-05-16T05:44:15Z</dc:date>
    </item>
  </channel>
</rss>

