<?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: I need help using sas with unix commands in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-UNIX-commands-with-SAS/m-p/961074#M45859</link>
    <description>&lt;P&gt;We cannot help you access files you are not allowed to access.&lt;/P&gt;
&lt;P&gt;We could suggest better SAS code that what you showed.&lt;/P&gt;
&lt;P&gt;If you just want to get a list of files you do not need to use operating system commands.&lt;/P&gt;
&lt;P&gt;For example you could use this macro:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/sasutils/macros/blob/master/dirtree.sas" target="_blank"&gt;https://github.com/sasutils/macros/blob/master/dirtree.sas&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 06 Mar 2025 15:05:03 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2025-03-06T15:05:03Z</dc:date>
    <item>
      <title>Using UNIX commands with SAS</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-UNIX-commands-with-SAS/m-p/961056#M45856</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I am trying sas code with unix commands to read all directories /sub directories(in unix - IPswitch) but few folders don't have permission to read so I am getting cannot access in the log those report folders need to be captured in a dataset along with folder level owner/group information. Could you please help with that to crack?&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Code used:&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;Data all_files;&lt;/DIV&gt;
&lt;DIV&gt;length&amp;nbsp; folder $600. file_name $256&amp;nbsp; owner $50 size 8 mod_date $12 mod_time $5&amp;nbsp; main_path$600. permissions $10 links 8&amp;nbsp; group $50 ;&lt;/DIV&gt;
&lt;DIV&gt;main_path=compress(cats(folder||'/'||file_name));&lt;/DIV&gt;
&lt;DIV&gt;if file_name ^=' ';&lt;/DIV&gt;
&lt;DIV&gt;run;&lt;/DIV&gt;
&lt;DIV&gt;%macro read_folders(base_dir);&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;filename dirlist pipe "find &amp;amp;base_dir -type d";&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;data directories;&lt;/DIV&gt;
&lt;DIV&gt;infile dirlist truncover;&lt;/DIV&gt;
&lt;DIV&gt;input&amp;nbsp; folder_path $600.;&lt;/DIV&gt;
&lt;DIV&gt;if folder_path ne '';&lt;/DIV&gt;
&lt;DIV&gt;run;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;%if %sysfunc(exist(directories)) %then %do;&lt;/DIV&gt;
&lt;DIV&gt;data _null_;&lt;/DIV&gt;
&lt;DIV&gt;set directories nobs=num_dirs;&lt;/DIV&gt;
&lt;DIV&gt;call symput('num_dirs', num_dirs);&lt;/DIV&gt;
&lt;DIV&gt;run;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;%if &amp;amp;num_dirs &amp;gt;0 %then %do;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; data _null_;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;set directories ;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;call symputx('current_folder'||left(_n_), strip(folder_path));&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;%do i=1 %to &amp;amp;num_dirs;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; filename filelist pipe "ls -lt --time-style=long-iso &amp;amp;&amp;amp;current_folder&amp;amp;i";&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;Data files_&amp;amp;i ;&lt;/DIV&gt;
&lt;DIV&gt;infile filelist truncover;&lt;/DIV&gt;
&lt;DIV&gt;length line $1024;&lt;/DIV&gt;
&lt;DIV&gt;input line $1024.;&lt;/DIV&gt;
&lt;DIV&gt;if substr(line,1,1)&amp;nbsp; in ('t','') then delete;&lt;/DIV&gt;
&lt;DIV&gt;length permissions $10 links 8 owner $50 group $50 size 8 mod_date $12 mod_time $5 file_name $256 folder $600 datemodified 8;&lt;/DIV&gt;
&lt;DIV&gt;permissions =scan(line,1,' ');&lt;/DIV&gt;
&lt;DIV&gt;links=input(scan(line,2,' '),8.);&lt;/DIV&gt;
&lt;DIV&gt;owner=scan(line,3,' ');&lt;/DIV&gt;
&lt;DIV&gt;group=scan(line,4,' ');&lt;/DIV&gt;
&lt;DIV&gt;size=input(scan(line,5,' '),8.);&lt;/DIV&gt;
&lt;DIV&gt;mod_date=scan(line,6,' ');&lt;/DIV&gt;
&lt;DIV&gt;mod_time=scan(line,7, ' ');&lt;/DIV&gt;
&lt;DIV&gt;/*file_name=scan(line, -1, ' ');*/&lt;/DIV&gt;
&lt;DIV&gt;length prefix $1024;&lt;/DIV&gt;
&lt;DIV&gt;prefix=catx(' ',permissions,links,owner,group,size,scan(line,6, ' '),scan(line,7, ' '));&lt;/DIV&gt;
&lt;DIV&gt;start_pos=lengthn(prefix) +2;&lt;/DIV&gt;
&lt;DIV&gt;file_name=strip(substr(line,start_pos));&lt;/DIV&gt;
&lt;DIV&gt;file_name=prxchange('s/^\d+\s*//', -1,file_name);&lt;/DIV&gt;
&lt;DIV&gt;datemodified=input(catx(' ',mod_date,mod_time),anydtdtm20.);&lt;/DIV&gt;
&lt;DIV&gt;format datemodified dateteime19.;&lt;/DIV&gt;
&lt;DIV&gt;folder="&amp;amp;&amp;amp;current_folder&amp;amp;i";&lt;/DIV&gt;
&lt;DIV&gt;main_path=cats(folder,'/',file_name);&lt;/DIV&gt;
&lt;DIV&gt;if file_name^= ' ';&lt;/DIV&gt;
&lt;DIV&gt;run;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;proc append base=all_files data=files_&amp;amp;i force;&lt;/DIV&gt;
&lt;DIV&gt;run;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;%end;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;Proc print data=all_files; title "All Files with details"; run;&lt;/DIV&gt;
&lt;DIV&gt;%end;&lt;/DIV&gt;
&lt;DIV&gt;%else %do;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;%put ERROR: No directories found in &amp;amp;base_dir.;&lt;/DIV&gt;
&lt;DIV&gt;%end;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;%end;&lt;/DIV&gt;
&lt;DIV&gt;%else %do;&lt;/DIV&gt;
&lt;DIV&gt;%put ERROR: Unable to create directories dataset. Check the base directory path.;&lt;/DIV&gt;
&lt;DIV&gt;%end;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;%mend;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;%read_folders(/home/apps/acctopts/PROCESSES);&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Mar 2025 15:41:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-UNIX-commands-with-SAS/m-p/961056#M45856</guid>
      <dc:creator>Universe</dc:creator>
      <dc:date>2025-03-06T15:41:08Z</dc:date>
    </item>
    <item>
      <title>Re: I need help using sas with unix commands</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-UNIX-commands-with-SAS/m-p/961058#M45857</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/474035"&gt;@Universe&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;perhaps I am not understanding you, as you are requesting help with code, however it seems to me as your issue is with permissions. If the user that is owner of the SAS process does not have the right permissions, it won't be able to perform certain actions. You probably should align with our Unix admin.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This being said, I can see your code is quite elaborate for the required listing for which I commend you for.&lt;/P&gt;
&lt;P&gt;However, since you are already using linux commands, perhaps you could use linux commands to do that job, much more simpler and with less lines of code.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Some examples:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;tree -nf  | awk '{printf $0} {system("stat -c \" [ %y ]\" " $NF )}'| sed -e 's#\([0-9][0-9]:[0-9][0-9]:[0-9][0-9]\).*#\1 ]#g'  2&amp;gt;/dev/null&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE&gt;ls -Rl --time-style=long-iso /path/to/directory&lt;/CODE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE&gt;tree -D&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Mar 2025 13:11:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-UNIX-commands-with-SAS/m-p/961058#M45857</guid>
      <dc:creator>JuanS_OCS</dc:creator>
      <dc:date>2025-03-06T13:11:09Z</dc:date>
    </item>
    <item>
      <title>Re: I need help using sas with unix commands</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-UNIX-commands-with-SAS/m-p/961060#M45858</link>
      <description>&lt;P&gt;If you can't access the files from the LINUX/ UNIX/ any operating system command line why should the user be able to circumvent the system security features such as permissions to do things in SAS?!?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think the system administrator would be very cross with all involved. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If a user &lt;STRONG&gt;needs&lt;/STRONG&gt; access then talk the admin about changing permissions.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Mar 2025 13:34:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-UNIX-commands-with-SAS/m-p/961060#M45858</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2025-03-06T13:34:34Z</dc:date>
    </item>
    <item>
      <title>Re: I need help using sas with unix commands</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-UNIX-commands-with-SAS/m-p/961074#M45859</link>
      <description>&lt;P&gt;We cannot help you access files you are not allowed to access.&lt;/P&gt;
&lt;P&gt;We could suggest better SAS code that what you showed.&lt;/P&gt;
&lt;P&gt;If you just want to get a list of files you do not need to use operating system commands.&lt;/P&gt;
&lt;P&gt;For example you could use this macro:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/sasutils/macros/blob/master/dirtree.sas" target="_blank"&gt;https://github.com/sasutils/macros/blob/master/dirtree.sas&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Mar 2025 15:05:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-UNIX-commands-with-SAS/m-p/961074#M45859</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-03-06T15:05:03Z</dc:date>
    </item>
  </channel>
</rss>

