<?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: X cmd in a DI Studio job in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/X-cmd-in-a-DI-Studio-job/m-p/354905#M273922</link>
    <description>&lt;P&gt;Patrick,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the help. I'll read up on the articles you sent links to and make some changes in my program. Hopefully this will give me the needed feedback to see where things are going wrong, or it will be successful finally.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards.&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>Mon, 01 May 2017 13:06:03 GMT</pubDate>
    <dc:creator>cnilsen</dc:creator>
    <dc:date>2017-05-01T13:06:03Z</dc:date>
    <item>
      <title>X cmd in a DI Studio job</title>
      <link>https://communities.sas.com/t5/SAS-Programming/X-cmd-in-a-DI-Studio-job/m-p/354185#M273916</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My headache for today seems simple in theory, but I cannot get it to work:&lt;/P&gt;&lt;P&gt;At the end of a DI Studio job (v 4.901) , in the postcode of a transformation, I want to execute an X cmd to delete tables in my archive directory that are over 7 days old. Sounds easy enough right?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;in this transformation, I am already using an X cmd to copy the file I just processed into an archive folder based on the status of the job being 'successful'. This works with no problems whatsoever:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;X cp -a /dmadata/AS400/CDH_* /dmadata/AS400_ARCH/;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now after this, I also want to delete any tables in this same archive directory that are older than 7 days.&lt;/P&gt;&lt;P&gt;I have tried several variations of :&lt;/P&gt;&lt;P&gt;x find /dmadata/AS400_ARCH/CDH* -mtime +7 -exec rm {} \; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the job runs without error, but doesnt do anything.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried to use this code without the mtime check, as well as with a fully defined table name.. but nothing works.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried this version:&lt;/P&gt;&lt;P&gt;x rm /dmadata/AS400_ARCH/CDH* ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and everything within the directory was deleted.. &amp;nbsp;so what's the issue? &amp;nbsp;&lt;/P&gt;&lt;P&gt;is there another piece I'm missing, or a format change that could work.? (and yes, I even moved this process to the front of my 'job' to see if it makes a difference, and the results were the same)&lt;/P&gt;&lt;P&gt;I'm stuck and looking for someone who might have had this same issue before..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&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>Thu, 27 Apr 2017 16:22:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/X-cmd-in-a-DI-Studio-job/m-p/354185#M273916</guid>
      <dc:creator>cnilsen</dc:creator>
      <dc:date>2017-04-27T16:22:00Z</dc:date>
    </item>
    <item>
      <title>Re: X cmd in a DI Studio job</title>
      <link>https://communities.sas.com/t5/SAS-Programming/X-cmd-in-a-DI-Studio-job/m-p/354449#M273917</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/103426"&gt;@cnilsen&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;That's definitely Unix/Linux scripting and not a SAS question.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;x find /dmadata/AS400_ARCH/CDH* -mtime +7 -exec rm {} \; &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;This command looks o.k. to me and I can find similar examples on the internet. I'd probably add "-type f" to your command so that you don't delete sub-directories by mistake.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;The only explanation I'm having: There are no files older than 7 days in your archive directory. Have you checked?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;If you want to preserve the "mtime" when copying files&amp;nbsp;to the archive then I believe you need also to use the "-p" switch as part of your cp command.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Apr 2017 12:42:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/X-cmd-in-a-DI-Studio-job/m-p/354449#M273917</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-04-28T12:42:00Z</dc:date>
    </item>
    <item>
      <title>Re: X cmd in a DI Studio job</title>
      <link>https://communities.sas.com/t5/SAS-Programming/X-cmd-in-a-DI-Studio-job/m-p/354457#M273918</link>
      <description>&lt;P&gt;Hi Patrick,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Everything I have looked at online, or with the help of a coworker shows it as a valid unix command. and, if I execute it in that environment.. it works perfectly. I dont understand why DI is having a hard time with it in this particular format. I have tried with and withiout the file type qualifier, as well as the date test. No luck either way.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Perhaps an issue with the -Exec or Find command?&amp;nbsp;&amp;nbsp;Becuase of the fact I am changing to a unix command, SAS doesnt log anything about this in the log.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I am doing my move/copy I am using the '-a' so that I can retain the original attributes of the table.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I figure I cant possibly be the only person to have had this issue...&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Apr 2017 13:01:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/X-cmd-in-a-DI-Studio-job/m-p/354457#M273918</guid>
      <dc:creator>cnilsen</dc:creator>
      <dc:date>2017-04-28T13:01:28Z</dc:date>
    </item>
    <item>
      <title>Re: X cmd in a DI Studio job</title>
      <link>https://communities.sas.com/t5/SAS-Programming/X-cmd-in-a-DI-Studio-job/m-p/354503#M273919</link>
      <description>If you want feed back, don't use X. If this is SAS tables, using PROC DATASETS seem more appropriate.</description>
      <pubDate>Fri, 28 Apr 2017 15:14:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/X-cmd-in-a-DI-Studio-job/m-p/354503#M273919</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2017-04-28T15:14:51Z</dc:date>
    </item>
    <item>
      <title>Re: X cmd in a DI Studio job</title>
      <link>https://communities.sas.com/t5/SAS-Programming/X-cmd-in-a-DI-Studio-job/m-p/354508#M273920</link>
      <description>LinusH-&lt;BR /&gt;&lt;BR /&gt;These are not SAS tables. they are actually delimited files on a unix server that I process with DI Studio and into a SAS table. I am able to execute the X cmd to move the delimited tables into an archive directory also on the unix box. I was also hoping to use X to delete older tables within that same archive directory as part of the same job.</description>
      <pubDate>Fri, 28 Apr 2017 15:30:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/X-cmd-in-a-DI-Studio-job/m-p/354508#M273920</guid>
      <dc:creator>cnilsen</dc:creator>
      <dc:date>2017-04-28T15:30:27Z</dc:date>
    </item>
    <item>
      <title>Re: X cmd in a DI Studio job</title>
      <link>https://communities.sas.com/t5/SAS-Programming/X-cmd-in-a-DI-Studio-job/m-p/354679#M273921</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/103426"&gt;@cnilsen&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;I've done similar things than what you're trying to do and they work out of SAS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let's first get DIS out of the way. You're using user written code and DIS is here nothing else than the client which you use to send code to the SAS server for execution. The code as such won't get changed by DIS and you could run this code also out of another client (ie. EG or SAS Studio) which connects to the same environment.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;On the SAS server side when using an X command: This command should in principle just get passed to the host for execution.You might have to add some quoting and masking if you use characters like &amp;amp; which&amp;nbsp;are SAS Macro tokens.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to capture the feedback from the OS for your command then don't use an X command but a filename pipe as explained here:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.sas.com/content/sgf/2016/03/11/using-a-pipe-to-return-the-output-of-an-operating-system-command-to-sas-software/&amp;nbsp;" target="_blank"&gt;http://blogs.sas.com/content/sgf/2016/03/11/using-a-pipe-to-return-the-output-of-an-operating-system-command-to-sas-software/&amp;nbsp;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks to&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35204"&gt;@JuanS_OCS&lt;/a&gt;&amp;nbsp;who has pointed me into the right direction using a pipe in his answer to this question:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/Administration-and-Deployment/sas-recover-metadata-executed-via-call-system-out-of-SAS-EG/m-p/341518/highlight/true#M7934&amp;nbsp;" target="_blank"&gt;https://communities.sas.com/t5/Administration-and-Deployment/sas-recover-metadata-executed-via-call-system-out-of-SAS-EG/m-p/341518/highlight/true#M7934&amp;nbsp;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 29 Apr 2017 04:10:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/X-cmd-in-a-DI-Studio-job/m-p/354679#M273921</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-04-29T04:10:21Z</dc:date>
    </item>
    <item>
      <title>Re: X cmd in a DI Studio job</title>
      <link>https://communities.sas.com/t5/SAS-Programming/X-cmd-in-a-DI-Studio-job/m-p/354905#M273922</link>
      <description>&lt;P&gt;Patrick,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the help. I'll read up on the articles you sent links to and make some changes in my program. Hopefully this will give me the needed feedback to see where things are going wrong, or it will be successful finally.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards.&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>Mon, 01 May 2017 13:06:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/X-cmd-in-a-DI-Studio-job/m-p/354905#M273922</guid>
      <dc:creator>cnilsen</dc:creator>
      <dc:date>2017-05-01T13:06:03Z</dc:date>
    </item>
    <item>
      <title>Re: X cmd in a DI Studio job</title>
      <link>https://communities.sas.com/t5/SAS-Programming/X-cmd-in-a-DI-Studio-job/m-p/354956#M273923</link>
      <description>&lt;P&gt;You haven't quoted the string that you are passing to the X command, so that can cause errors.&lt;/P&gt;
&lt;P&gt;For example in this one the semi-colon is part of the FIND command, but SAS will instead take it as marking the end of the X command which is probably what is causing your command not to run.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;x find /dmadata/AS400_ARCH/CDH* -mtime +7 -exec rm {} \;  &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could change from using \; to + in the find command. A change that you probably want any way.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;x find /dmadata/AS400_ARCH/CDH* -mtime +7 -exec rm {} +;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could add the quotes.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;x 'find /dmadata/AS400_ARCH/CDH* -mtime +7 -exec rm {} +';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What I like to do is use a DATA step to run commands. That way you can read the output. For example you could tell the FIND command to list the files that it found befor it removes them.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  infile 'find /dmadata/AS400_ARCH/CDH* -mtime +7 -ls -exec rm {} +' pipe;
  input;
  put _infile_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 May 2017 14:57:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/X-cmd-in-a-DI-Studio-job/m-p/354956#M273923</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-05-01T14:57:40Z</dc:date>
    </item>
    <item>
      <title>Re: X cmd in a DI Studio job</title>
      <link>https://communities.sas.com/t5/SAS-Programming/X-cmd-in-a-DI-Studio-job/m-p/355020#M273924</link>
      <description>Thanks for the idea Tom,&lt;BR /&gt;I'm relatively new to SAS so this is an option I had known about. I'll give it a try and see what happens.&lt;BR /&gt;&lt;BR /&gt;I appreciate you using my code to do the data step.. I can more easily see how the process works.&lt;BR /&gt;&lt;BR /&gt;Regards.&lt;BR /&gt;</description>
      <pubDate>Mon, 01 May 2017 18:45:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/X-cmd-in-a-DI-Studio-job/m-p/355020#M273924</guid>
      <dc:creator>cnilsen</dc:creator>
      <dc:date>2017-05-01T18:45:08Z</dc:date>
    </item>
  </channel>
</rss>

