<?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: Reading in SAS program and not seeing the formatting the way  it should look (tabs/spaces/etc.) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Reading-in-SAS-program-and-not-seeing-the-formatting-the-way-it/m-p/952795#M372352</link>
    <description>&lt;P&gt;Get it to work properly for single files before trying to wrap it into macro code.&amp;nbsp; Whether the results "look" right or not is not related to the macro logic you showed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why did you throw away the empty lines?&amp;nbsp; Do you not want them in the end result?&amp;nbsp; If you need the empty lines it is easier to keep them than they to add them back when writing the results back out.&amp;nbsp; Make sure to use COMPRESS=YES and it does not really have much impact on the filesize to include the empty lines.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why are you using PAD instead of TRUNCOVER on your INFILE statement?&amp;nbsp; Or since you seem to want the whole line why not just use the automatic _INFILE_ variable?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you care about trailing spaces on the lines?&amp;nbsp; If you do then you will need to update your input step to remember how long the source lines were.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data prg_desc_&amp;amp;i.(compress=yes);   
  length line_counter linesize 8 intext $32767 ;  
  line_counter + 1;
  infile "&amp;amp;fldr_id.\&amp;amp;in_prg..sas" lrecl=32767 length=ll ;
  input;
  linesize=ll;
  intext=_infile_;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;When writing the lines back out use $CHAR or $VARYING format to preserve the leading spaces.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set prg_desc_&amp;amp;i. ;
  file NEWFILE lrecl=32767 ;
  put intext $varying32716. linesize;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you don't need to preserve the trialing spaces (and why would you in a program file??) then calculate LINESIZE using the LENGTHN() function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set prg_desc_&amp;amp;i. ;
  file NEWFILE lrecl=32767 ;
  linesize=length(intext);
  put intext $varying32716. linesize;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And if it turns out your original issue is just to do with tabs in the source code then you might want to use the EXPANDTABS option of the INFILE statement when reading the files.&amp;nbsp; But be careful because programmers that allow TAB characters in their programs might also allow tab characters inside the string literals in their code.&amp;nbsp; I have seen a lot of questions being asked on this forum about when code to read a tab delimited file written with DLM=' ' (where there is a literal TAB character inside the quotes) fails to work when run from SAS Display Manager.&amp;nbsp; It is because Display Manager knows to replace tabs with spaces before submitting the code to the SAS compiler to run.&lt;/P&gt;</description>
    <pubDate>Fri, 06 Dec 2024 22:28:21 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2024-12-06T22:28:21Z</dc:date>
    <item>
      <title>Reading in SAS program and not seeing the formatting the way  it should look (tabs/spaces/etc.)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-in-SAS-program-and-not-seeing-the-formatting-the-way-it/m-p/952781#M372349</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm using this sequence to read in a series of SAS programs:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;%macro run_loop;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; %do i=1 %to &amp;amp;cntlist.;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; %let in_prg=%scan(&amp;amp;varlist.,&amp;amp;i.);&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; %let fldr_id = %scan(&amp;amp;dirlist., &amp;amp;i., '^');&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; *------------------------------------------------------------------;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; *------------------------------------------------------------------;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; * READ IN EACH PROGRAM AND REPLACE OLD PURPOSE WITH NEW PURPOSE&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; *------------------------------------------------------------------;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; *------------------------------------------------------------------;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; /*READ IN EACH PROGRAM*/&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; data prg_desc_&amp;amp;i.;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; infile "&amp;amp;fldr_id.\&amp;amp;in_prg..sas" lrecl=32767 pad;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; input intext $char32767.;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; line_counter + 1;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if intext ne ' ';&lt;/DIV&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;%end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%mend run_loop;&lt;BR /&gt;%run_loop;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want the data files built using the programs to retain all of the underlying formatting (spaces, tabs, etc.) . There is SOME of that (ie, it's not left aligned) but it does look different from the actual program, which has many more spaces, tabs, etc. on each line.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example, when I open the program I see:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PURPOSE: ABC&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DEF&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; GHI&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But when I run my program, it's not so spaced out:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PURPOSE: ABC&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DEF&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; GHI&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there a way to set this up so my read-in gives me the exact underlying program line values with all formatting intact?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Fri, 06 Dec 2024 21:28:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-in-SAS-program-and-not-seeing-the-formatting-the-way-it/m-p/952781#M372349</guid>
      <dc:creator>Walternate</dc:creator>
      <dc:date>2024-12-06T21:28:30Z</dc:date>
    </item>
    <item>
      <title>Re: Reading in SAS program and not seeing the formatting the way  it should look (tabs/spaces/etc.)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-in-SAS-program-and-not-seeing-the-formatting-the-way-it/m-p/952782#M372350</link>
      <description>&lt;P&gt;Is it possible your .sas program has leading tabs on some lines and leading spaces on others?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Without getting into the war of tabs vs spaces in code, if you have tab characters in your code, they will be interpreted differently depending on the application you use to open them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You might also want to describe the big picture of what you're doing, as people might have other ideas.&amp;nbsp; Are you planning to read the code from a .sas file into a data set, and then use a DATA step to update the code, and then write a new .sas file?&lt;/P&gt;</description>
      <pubDate>Fri, 06 Dec 2024 21:43:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-in-SAS-program-and-not-seeing-the-formatting-the-way-it/m-p/952782#M372350</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2024-12-06T21:43:21Z</dc:date>
    </item>
    <item>
      <title>Re: Reading in SAS program and not seeing the formatting the way  it should look (tabs/spaces/etc.)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-in-SAS-program-and-not-seeing-the-formatting-the-way-it/m-p/952783#M372351</link>
      <description>&lt;P&gt;You need to explain more what you mean.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you talking about the values of the variable INTEXT&amp;nbsp;&lt;SPAN&gt;that you are creating with this line:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; input intext $char32767.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;How are you LOOKING at the values?&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Did you write them back out to a NEW file?&amp;nbsp; If so what code did you use?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Did you use PROC PRINT?&amp;nbsp; If so what output destination did you use? ODS does not not normally preserve leading spaces or use FIXED WIDTH fonts.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Did you accidentally allow the original programs to be created with embedded TAB characters?&amp;nbsp; What text editor did you use to create those original programs?&amp;nbsp; What tab stop settings did you have in place when editing the files?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Dec 2024 21:48:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-in-SAS-program-and-not-seeing-the-formatting-the-way-it/m-p/952783#M372351</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-12-06T21:48:10Z</dc:date>
    </item>
    <item>
      <title>Re: Reading in SAS program and not seeing the formatting the way  it should look (tabs/spaces/etc.)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-in-SAS-program-and-not-seeing-the-formatting-the-way-it/m-p/952795#M372352</link>
      <description>&lt;P&gt;Get it to work properly for single files before trying to wrap it into macro code.&amp;nbsp; Whether the results "look" right or not is not related to the macro logic you showed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why did you throw away the empty lines?&amp;nbsp; Do you not want them in the end result?&amp;nbsp; If you need the empty lines it is easier to keep them than they to add them back when writing the results back out.&amp;nbsp; Make sure to use COMPRESS=YES and it does not really have much impact on the filesize to include the empty lines.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why are you using PAD instead of TRUNCOVER on your INFILE statement?&amp;nbsp; Or since you seem to want the whole line why not just use the automatic _INFILE_ variable?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you care about trailing spaces on the lines?&amp;nbsp; If you do then you will need to update your input step to remember how long the source lines were.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data prg_desc_&amp;amp;i.(compress=yes);   
  length line_counter linesize 8 intext $32767 ;  
  line_counter + 1;
  infile "&amp;amp;fldr_id.\&amp;amp;in_prg..sas" lrecl=32767 length=ll ;
  input;
  linesize=ll;
  intext=_infile_;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;When writing the lines back out use $CHAR or $VARYING format to preserve the leading spaces.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set prg_desc_&amp;amp;i. ;
  file NEWFILE lrecl=32767 ;
  put intext $varying32716. linesize;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you don't need to preserve the trialing spaces (and why would you in a program file??) then calculate LINESIZE using the LENGTHN() function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set prg_desc_&amp;amp;i. ;
  file NEWFILE lrecl=32767 ;
  linesize=length(intext);
  put intext $varying32716. linesize;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And if it turns out your original issue is just to do with tabs in the source code then you might want to use the EXPANDTABS option of the INFILE statement when reading the files.&amp;nbsp; But be careful because programmers that allow TAB characters in their programs might also allow tab characters inside the string literals in their code.&amp;nbsp; I have seen a lot of questions being asked on this forum about when code to read a tab delimited file written with DLM=' ' (where there is a literal TAB character inside the quotes) fails to work when run from SAS Display Manager.&amp;nbsp; It is because Display Manager knows to replace tabs with spaces before submitting the code to the SAS compiler to run.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Dec 2024 22:28:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-in-SAS-program-and-not-seeing-the-formatting-the-way-it/m-p/952795#M372352</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-12-06T22:28:21Z</dc:date>
    </item>
  </channel>
</rss>

