<?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 output put statements into a text file in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/macro-to-output-put-statements-into-a-text-file/m-p/229734#M41596</link>
    <description>&lt;P&gt;To create a file for&amp;nbsp;each company&amp;nbsp;you can use macro:&lt;/P&gt;
&lt;P&gt;%macro test();&lt;/P&gt;
&lt;P&gt;proc sql noprint;&lt;/P&gt;
&lt;P&gt;select distinct(company) into: _comlst separated by "#"&lt;/P&gt;
&lt;P&gt;from indata;&lt;/P&gt;
&lt;P&gt;select count(distinct(company)) into: _comnum&lt;/P&gt;
&lt;P&gt;from indata;&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%do i=1 %to &amp;amp;_comnum;&lt;/P&gt;
&lt;P&gt;%let currcomp=%scan(&amp;amp;_complst.,&amp;amp;i,#);&lt;/P&gt;
&lt;P&gt;data _null_;&lt;/P&gt;
&lt;P&gt;set indata;&lt;/P&gt;
&lt;P&gt;where company="&amp;amp;currcomp.";&lt;/P&gt;
&lt;P&gt;file "&amp;amp;currcomp..txt";&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;%end;&lt;/P&gt;
&lt;P&gt;%mend;&lt;/P&gt;</description>
    <pubDate>Tue, 13 Oct 2015 15:58:24 GMT</pubDate>
    <dc:creator>ndp</dc:creator>
    <dc:date>2015-10-13T15:58:24Z</dc:date>
    <item>
      <title>macro to output put statements into a text file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-to-output-put-statements-into-a-text-file/m-p/229340#M41505</link>
      <description>&lt;P&gt;Hello all-&lt;/P&gt;
&lt;P&gt;Happy Friday-&lt;/P&gt;
&lt;P&gt;I am writing this out to get some general ideas on how to approach the problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Suppoded I have two companies-ABC and DEF, and with each a subset of variables-codes&amp;nbsp;&lt;/P&gt;
&lt;P&gt;for example&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ABC G9&lt;/P&gt;
&lt;P&gt;ABC G11&lt;/P&gt;
&lt;P&gt;ABC G25&lt;/P&gt;
&lt;P&gt;DEF G15&lt;/P&gt;
&lt;P&gt;DEF G27&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What I want to do is produce a text file for each company.i.e. ABC.text, DEF.text&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In each text file, I need to cycle through the codes in such a way that each file would have-&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hello world&lt;/P&gt;
&lt;P&gt;Hello G9&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Goodbye&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hello world&lt;/P&gt;
&lt;P&gt;Hello G11&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Goodbye &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hello world&lt;/P&gt;
&lt;P&gt;Hello G2000&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Goodbye&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;what I am doing is a lot more complicated but I think if I get the gist then I can carry on-&lt;/P&gt;
&lt;P&gt;basically I am outputting a dynamic vba script.What I am really doing is outputting a bunch of statements. I can't include real data as it is highly sensitive-&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The VBA script actually works as well as the VBS script-now I just need to macro the heck out of it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What I can do is output individual files for each iteration but I do not want to do that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;%macro pdf(data=, var=, var1=,var2=,var3=);&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; proc sort data=&amp;amp;data(keep=&amp;amp;var &amp;amp;var1 &amp;amp;var2 &amp;amp;var3) out=values nodupkey;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; by &amp;amp;var;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; run;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; data _null_;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set values end=last;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; call symputx('site'||left(_n_),&amp;amp;var);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; call symputx('sitea'||left(_n_),&amp;amp;var1);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; call symputx('siteb'||left(_n_),&amp;amp;var2);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; call symputx('sitec'||left(_n_),&amp;amp;var3);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if last then call symputx('count',_n_);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;select(&amp;amp;var);&lt;BR /&gt;%do i=1 %to &amp;amp;count;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;put "Attribute VB_Name = ""Module1"" ";&lt;BR /&gt;put "Sub &amp;amp;&amp;amp;site&amp;amp;i()";&lt;BR /&gt;put "ActiveSheet.Range(""&amp;amp;&amp;amp;sitec&amp;amp;i"").Select";&lt;BR /&gt;put "&amp;nbsp;&amp;nbsp; ActiveSheet.OLEObjects.Add Filename:=""T:\P_PPR\PPR_Program\QOS\PPR\NCAL_CG_Files\Complaints Details\2015MY\&amp;amp;&amp;amp;sitea&amp;amp;i"", Link _";&lt;BR /&gt;&lt;BR /&gt;put "&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; :=False, DisplayAsIcon:=True, IconFileName:= _ ";&lt;BR /&gt;&lt;BR /&gt;put "&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ""C:\windows\Installer\{AC76BA86-7AD7-FFFF-7B44-AB0000000001}\PDFFile_8.ico"", IconIndex:=0, IconLabel:= _";&lt;BR /&gt;&amp;nbsp;put "&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ""&amp;amp;&amp;amp;siteb&amp;amp;i"" ";&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;put&amp;nbsp;&amp;nbsp;&amp;nbsp; "ActiveSheet.OLEobjects.Height = 60";&lt;BR /&gt;put&amp;nbsp;&amp;nbsp; "ActiveSheet.OLEObjects.Width = 50";&lt;BR /&gt;put&amp;nbsp; "End Sub";&lt;BR /&gt;&lt;BR /&gt;put fruit;&lt;BR /&gt;datalines;&lt;BR /&gt;end&lt;BR /&gt;&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;%end; &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;%mend;&lt;BR /&gt;%pdf(data=MED_ROS,var=MACRONAME,var1=pdf_file,var2=NAMEX,var3=PLACEHOLD);&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;
&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Oct 2015 18:12:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-to-output-put-statements-into-a-text-file/m-p/229340#M41505</guid>
      <dc:creator>LB</dc:creator>
      <dc:date>2015-10-09T18:12:22Z</dc:date>
    </item>
    <item>
      <title>Re: macro to output put statements into a text file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-to-output-put-statements-into-a-text-file/m-p/229342#M41506</link>
      <description>&lt;P&gt;I don't think a macro is needed here at all, a DATA step will do this. UNTESTED CODE&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data oink;
    file "external_file.txt";
    input id $ id2 $;
    put "Hello, World" / Hello" id2 $8. // "Goodbye";
    cards;
ABC G9
ABC G11
ABC G25
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 09 Oct 2015 18:26:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-to-output-put-statements-into-a-text-file/m-p/229342#M41506</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2015-10-09T18:26:36Z</dc:date>
    </item>
    <item>
      <title>Re: macro to output put statements into a text file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-to-output-put-statements-into-a-text-file/m-p/229398#M41514</link>
      <description>&lt;P&gt;How about writing the DATA steps to a file?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data _null_;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;file 'file_holding_all_the_SAS_code_needed.txt' noprint;&lt;/P&gt;
&lt;P&gt;by company;&lt;/P&gt;
&lt;P&gt;if first.company then put 'file "' company +(-1) '.txt" noprint;';&lt;/P&gt;
&lt;P&gt;put 'put "Hello world";';&lt;/P&gt;
&lt;P&gt;put 'put "Hello "' company +(-1) ';' ;&lt;/P&gt;
&lt;P&gt;put 'put / "Goodbye";';&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data _null_;&lt;/P&gt;
&lt;P&gt;%include 'file_holding_all_the_SAS_code_needed.txt';&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's untested and gives you a headache just looking at it ... but it's at least a workable approach.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good luck.&lt;/P&gt;</description>
      <pubDate>Sat, 10 Oct 2015 01:14:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-to-output-put-statements-into-a-text-file/m-p/229398#M41514</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2015-10-10T01:14:09Z</dc:date>
    </item>
    <item>
      <title>Re: macro to output put statements into a text file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-to-output-put-statements-into-a-text-file/m-p/229557#M41555</link>
      <description>PaigeMiller-&lt;BR /&gt;This works fairly well-One question though-&lt;BR /&gt;Let's say I want to add something at beginning or end&lt;BR /&gt;i.e.= "Start world " That would be the first line in the file but then not repeat? &lt;BR /&gt;&lt;BR /&gt;Thanks for your assistance</description>
      <pubDate>Mon, 12 Oct 2015 16:05:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-to-output-put-statements-into-a-text-file/m-p/229557#M41555</guid>
      <dc:creator>LB</dc:creator>
      <dc:date>2015-10-12T16:05:51Z</dc:date>
    </item>
    <item>
      <title>Re: macro to output put statements into a text file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-to-output-put-statements-into-a-text-file/m-p/229676#M41582</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding﻿&lt;/a&gt;&lt;/P&gt;&lt;P&gt;I think there's a much simpler way&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data oink;
    file "external_file.txt";
    input id $ id2 $;
    if _n_=1 then put "Start World";
    put "Hello, World" / Hello" id2 $8. // "Goodbye";
    cards;
ABC G9
ABC G11
ABC G25
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Oct 2015 11:26:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-to-output-put-statements-into-a-text-file/m-p/229676#M41582</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2015-10-13T11:26:06Z</dc:date>
    </item>
    <item>
      <title>Re: macro to output put statements into a text file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-to-output-put-statements-into-a-text-file/m-p/229707#M41590</link>
      <description>&lt;P&gt;Paige,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I added the complications because of one requirement ... creating a separate file for each company.&amp;nbsp; How do you create ABC.txt, DEF.txt, etc.?&lt;/P&gt;</description>
      <pubDate>Tue, 13 Oct 2015 14:02:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-to-output-put-statements-into-a-text-file/m-p/229707#M41590</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2015-10-13T14:02:25Z</dc:date>
    </item>
    <item>
      <title>Re: macro to output put statements into a text file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-to-output-put-statements-into-a-text-file/m-p/229734#M41596</link>
      <description>&lt;P&gt;To create a file for&amp;nbsp;each company&amp;nbsp;you can use macro:&lt;/P&gt;
&lt;P&gt;%macro test();&lt;/P&gt;
&lt;P&gt;proc sql noprint;&lt;/P&gt;
&lt;P&gt;select distinct(company) into: _comlst separated by "#"&lt;/P&gt;
&lt;P&gt;from indata;&lt;/P&gt;
&lt;P&gt;select count(distinct(company)) into: _comnum&lt;/P&gt;
&lt;P&gt;from indata;&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%do i=1 %to &amp;amp;_comnum;&lt;/P&gt;
&lt;P&gt;%let currcomp=%scan(&amp;amp;_complst.,&amp;amp;i,#);&lt;/P&gt;
&lt;P&gt;data _null_;&lt;/P&gt;
&lt;P&gt;set indata;&lt;/P&gt;
&lt;P&gt;where company="&amp;amp;currcomp.";&lt;/P&gt;
&lt;P&gt;file "&amp;amp;currcomp..txt";&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;%end;&lt;/P&gt;
&lt;P&gt;%mend;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Oct 2015 15:58:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-to-output-put-statements-into-a-text-file/m-p/229734#M41596</guid>
      <dc:creator>ndp</dc:creator>
      <dc:date>2015-10-13T15:58:24Z</dc:date>
    </item>
    <item>
      <title>Re: macro to output put statements into a text file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-to-output-put-statements-into-a-text-file/m-p/229751#M41599</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt; wrote:&lt;BR /&gt;&lt;P&gt;Paige,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I added the complications because of one requirement ... creating a separate file for each company.&amp;nbsp; How do you create ABC.txt, DEF.txt, etc.?&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;The FILEVAR= option allows this in a datastep.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Oct 2015 17:03:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-to-output-put-statements-into-a-text-file/m-p/229751#M41599</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2015-10-13T17:03:26Z</dc:date>
    </item>
    <item>
      <title>Re: macro to output put statements into a text file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-to-output-put-statements-into-a-text-file/m-p/229773#M41606</link>
      <description>&lt;P&gt;Ahhh, life gets simpler by the day.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Oct 2015 18:46:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-to-output-put-statements-into-a-text-file/m-p/229773#M41606</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2015-10-13T18:46:38Z</dc:date>
    </item>
    <item>
      <title>Re: macro to output put statements into a text file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-to-output-put-statements-into-a-text-file/m-p/229822#M41629</link>
      <description>Very nice-&lt;BR /&gt;Thank you! &lt;BR /&gt;</description>
      <pubDate>Tue, 13 Oct 2015 21:54:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-to-output-put-statements-into-a-text-file/m-p/229822#M41629</guid>
      <dc:creator>LB</dc:creator>
      <dc:date>2015-10-13T21:54:11Z</dc:date>
    </item>
  </channel>
</rss>

