SAS fdelete macro wont delete .xml files





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I have a macro that is looping through a set of folders on the file system and deleting either .txt or .xml files:



%macro delete_all_txt_files_in_folder(folder, type);


%macro dummy;


%mend dummy;


filename filelist "&folder";

data _null_;

dir_id = dopen('filelist');
total_members = dnum(dir_id);

if total_members = . then total_members = 0;

do i = 1 to total_members;

member_name = dread(dir_id,i);

if scan(lowcase(member_name),2,'.')='&type.' then do;

file_id = mopen(dir_id,member_name,'i',0);

if file_id > 0 then do;

freadrc = fread(file_id);
rc = fclose(file_id);
rc = filename('delete',member_name,,,'filelist');
rc = fdelete('delete');

end;

rc = fclose(file_id);

end;

end;

rc = dclose(dir_id);

run;


%mend;


%delete_all_txt_files_in_folder(&rback_4., txt);
%delete_all_txt_files_in_folder(&rback_5., xml);
%delete_all_txt_files_in_folder(&rback_6., txt);
%delete_all_txt_files_in_folder(&rback_7., txt);


...however it does not want to delete the .xml files for some reason and I am not really sure why. Is there are restriction on what types of files fdelete can remove?



Thanks










share|improve this question


















  • 1





    There are no restrictions on fdelete for file types AFAIK. Are you getting an error message? Can you manually delete those files?

    – Reeza
    Nov 23 '18 at 17:37






  • 1





    Why does the macro need to read from the file before deleting it?

    – Tom
    Nov 23 '18 at 21:06











  • Perhaps this is a file permissions issue. Have you checked if the XML files have different permissions?

    – Craig Srsen
    Nov 24 '18 at 0:30


















0















I have a macro that is looping through a set of folders on the file system and deleting either .txt or .xml files:



%macro delete_all_txt_files_in_folder(folder, type);


%macro dummy;


%mend dummy;


filename filelist "&folder";

data _null_;

dir_id = dopen('filelist');
total_members = dnum(dir_id);

if total_members = . then total_members = 0;

do i = 1 to total_members;

member_name = dread(dir_id,i);

if scan(lowcase(member_name),2,'.')='&type.' then do;

file_id = mopen(dir_id,member_name,'i',0);

if file_id > 0 then do;

freadrc = fread(file_id);
rc = fclose(file_id);
rc = filename('delete',member_name,,,'filelist');
rc = fdelete('delete');

end;

rc = fclose(file_id);

end;

end;

rc = dclose(dir_id);

run;


%mend;


%delete_all_txt_files_in_folder(&rback_4., txt);
%delete_all_txt_files_in_folder(&rback_5., xml);
%delete_all_txt_files_in_folder(&rback_6., txt);
%delete_all_txt_files_in_folder(&rback_7., txt);


...however it does not want to delete the .xml files for some reason and I am not really sure why. Is there are restriction on what types of files fdelete can remove?



Thanks










share|improve this question


















  • 1





    There are no restrictions on fdelete for file types AFAIK. Are you getting an error message? Can you manually delete those files?

    – Reeza
    Nov 23 '18 at 17:37






  • 1





    Why does the macro need to read from the file before deleting it?

    – Tom
    Nov 23 '18 at 21:06











  • Perhaps this is a file permissions issue. Have you checked if the XML files have different permissions?

    – Craig Srsen
    Nov 24 '18 at 0:30














0












0








0








I have a macro that is looping through a set of folders on the file system and deleting either .txt or .xml files:



%macro delete_all_txt_files_in_folder(folder, type);


%macro dummy;


%mend dummy;


filename filelist "&folder";

data _null_;

dir_id = dopen('filelist');
total_members = dnum(dir_id);

if total_members = . then total_members = 0;

do i = 1 to total_members;

member_name = dread(dir_id,i);

if scan(lowcase(member_name),2,'.')='&type.' then do;

file_id = mopen(dir_id,member_name,'i',0);

if file_id > 0 then do;

freadrc = fread(file_id);
rc = fclose(file_id);
rc = filename('delete',member_name,,,'filelist');
rc = fdelete('delete');

end;

rc = fclose(file_id);

end;

end;

rc = dclose(dir_id);

run;


%mend;


%delete_all_txt_files_in_folder(&rback_4., txt);
%delete_all_txt_files_in_folder(&rback_5., xml);
%delete_all_txt_files_in_folder(&rback_6., txt);
%delete_all_txt_files_in_folder(&rback_7., txt);


...however it does not want to delete the .xml files for some reason and I am not really sure why. Is there are restriction on what types of files fdelete can remove?



Thanks










share|improve this question














I have a macro that is looping through a set of folders on the file system and deleting either .txt or .xml files:



%macro delete_all_txt_files_in_folder(folder, type);


%macro dummy;


%mend dummy;


filename filelist "&folder";

data _null_;

dir_id = dopen('filelist');
total_members = dnum(dir_id);

if total_members = . then total_members = 0;

do i = 1 to total_members;

member_name = dread(dir_id,i);

if scan(lowcase(member_name),2,'.')='&type.' then do;

file_id = mopen(dir_id,member_name,'i',0);

if file_id > 0 then do;

freadrc = fread(file_id);
rc = fclose(file_id);
rc = filename('delete',member_name,,,'filelist');
rc = fdelete('delete');

end;

rc = fclose(file_id);

end;

end;

rc = dclose(dir_id);

run;


%mend;


%delete_all_txt_files_in_folder(&rback_4., txt);
%delete_all_txt_files_in_folder(&rback_5., xml);
%delete_all_txt_files_in_folder(&rback_6., txt);
%delete_all_txt_files_in_folder(&rback_7., txt);


...however it does not want to delete the .xml files for some reason and I am not really sure why. Is there are restriction on what types of files fdelete can remove?



Thanks







xml sas






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 23 '18 at 17:25









gdogg371gdogg371

1,30663164




1,30663164








  • 1





    There are no restrictions on fdelete for file types AFAIK. Are you getting an error message? Can you manually delete those files?

    – Reeza
    Nov 23 '18 at 17:37






  • 1





    Why does the macro need to read from the file before deleting it?

    – Tom
    Nov 23 '18 at 21:06











  • Perhaps this is a file permissions issue. Have you checked if the XML files have different permissions?

    – Craig Srsen
    Nov 24 '18 at 0:30














  • 1





    There are no restrictions on fdelete for file types AFAIK. Are you getting an error message? Can you manually delete those files?

    – Reeza
    Nov 23 '18 at 17:37






  • 1





    Why does the macro need to read from the file before deleting it?

    – Tom
    Nov 23 '18 at 21:06











  • Perhaps this is a file permissions issue. Have you checked if the XML files have different permissions?

    – Craig Srsen
    Nov 24 '18 at 0:30








1




1





There are no restrictions on fdelete for file types AFAIK. Are you getting an error message? Can you manually delete those files?

– Reeza
Nov 23 '18 at 17:37





There are no restrictions on fdelete for file types AFAIK. Are you getting an error message? Can you manually delete those files?

– Reeza
Nov 23 '18 at 17:37




1




1





Why does the macro need to read from the file before deleting it?

– Tom
Nov 23 '18 at 21:06





Why does the macro need to read from the file before deleting it?

– Tom
Nov 23 '18 at 21:06













Perhaps this is a file permissions issue. Have you checked if the XML files have different permissions?

– Craig Srsen
Nov 24 '18 at 0:30





Perhaps this is a file permissions issue. Have you checked if the XML files have different permissions?

– Craig Srsen
Nov 24 '18 at 0:30












2 Answers
2






active

oldest

votes


















1














Macro expressions are not evaluated inside of single quotes.
Change



'&type.'


to



"&type."





share|improve this answer
























  • If that was the issue, it should't work for any file though?

    – Reeza
    Nov 23 '18 at 22:42



















0














Macro variables do not resolve in single quotes (unless using, for example, %BQUOTE('&VAR'))




if scan(lowcase(member_name),2,'.')='&type.' then do;


needs to be




if scan(lowcase(member_name),2,'.')="&type." then do;





share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53450808%2fsas-fdelete-macro-wont-delete-xml-files%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Macro expressions are not evaluated inside of single quotes.
    Change



    '&type.'


    to



    "&type."





    share|improve this answer
























    • If that was the issue, it should't work for any file though?

      – Reeza
      Nov 23 '18 at 22:42
















    1














    Macro expressions are not evaluated inside of single quotes.
    Change



    '&type.'


    to



    "&type."





    share|improve this answer
























    • If that was the issue, it should't work for any file though?

      – Reeza
      Nov 23 '18 at 22:42














    1












    1








    1







    Macro expressions are not evaluated inside of single quotes.
    Change



    '&type.'


    to



    "&type."





    share|improve this answer













    Macro expressions are not evaluated inside of single quotes.
    Change



    '&type.'


    to



    "&type."






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 23 '18 at 21:03









    TomTom

    24.9k2720




    24.9k2720













    • If that was the issue, it should't work for any file though?

      – Reeza
      Nov 23 '18 at 22:42



















    • If that was the issue, it should't work for any file though?

      – Reeza
      Nov 23 '18 at 22:42

















    If that was the issue, it should't work for any file though?

    – Reeza
    Nov 23 '18 at 22:42





    If that was the issue, it should't work for any file though?

    – Reeza
    Nov 23 '18 at 22:42













    0














    Macro variables do not resolve in single quotes (unless using, for example, %BQUOTE('&VAR'))




    if scan(lowcase(member_name),2,'.')='&type.' then do;


    needs to be




    if scan(lowcase(member_name),2,'.')="&type." then do;





    share|improve this answer




























      0














      Macro variables do not resolve in single quotes (unless using, for example, %BQUOTE('&VAR'))




      if scan(lowcase(member_name),2,'.')='&type.' then do;


      needs to be




      if scan(lowcase(member_name),2,'.')="&type." then do;





      share|improve this answer


























        0












        0








        0







        Macro variables do not resolve in single quotes (unless using, for example, %BQUOTE('&VAR'))




        if scan(lowcase(member_name),2,'.')='&type.' then do;


        needs to be




        if scan(lowcase(member_name),2,'.')="&type." then do;





        share|improve this answer













        Macro variables do not resolve in single quotes (unless using, for example, %BQUOTE('&VAR'))




        if scan(lowcase(member_name),2,'.')='&type.' then do;


        needs to be




        if scan(lowcase(member_name),2,'.')="&type." then do;






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 23 '18 at 21:04









        Chris JChris J

        6,41011824




        6,41011824






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53450808%2fsas-fdelete-macro-wont-delete-xml-files%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            If I really need a card on my start hand, how many mulligans make sense? [duplicate]

            Alcedinidae

            Can an atomic nucleus contain both particles and antiparticles? [duplicate]