Using SAS prxmatch to create variable










0














I would like to create new columns variable using criteria matched in prxmatch.



The first variable 'NEW' is Y if: 
a. (A= "YES", B="NO" and C="PRESENT") or
b. (B="NO" and C="MAYBE") or
c. (B="NO" and C in ("NO/FL", "T2/FL "))
else N
The second variable 'NEXT' is Y if:
A = 'NO' and B = 'NO' and E = 'Y'
else N
and the last variable NEWER is Y if
A = 'NEW'


Below is my code but I can't get prxmatch() to work



DATA TEST; 
SET TEST.TEST;
if A = 'NO' and B = 'YES' and C = 'PRESENT' then NEW = 'Y';
else if B = 'NO' and C = 'MAYBE' then NEW = 'Y';
else if prxmatch('m/NO/FL|T2/FL/oi', C) > 0 and B = 'NO' then NEW = 'Y';
else NEW = 'N';
if A = 'NO' and B = 'NO' and E = 'Y' then NEXT = 'Y';
else NEXT = 'N';
if A = 'NEW' then NEWER = 'Y';
RUN;

PROC PRINT DATA = TEST;
RUN;









share|improve this question























  • You need to provide some sample data, so that someone can help you to understand why it is not working
    – Kiran
    Nov 13 '18 at 2:10










  • Is the information in the first code block actually textual data representing logic rules that need to be evaluated against the data ?
    – Richard
    Nov 13 '18 at 13:17















0














I would like to create new columns variable using criteria matched in prxmatch.



The first variable 'NEW' is Y if: 
a. (A= "YES", B="NO" and C="PRESENT") or
b. (B="NO" and C="MAYBE") or
c. (B="NO" and C in ("NO/FL", "T2/FL "))
else N
The second variable 'NEXT' is Y if:
A = 'NO' and B = 'NO' and E = 'Y'
else N
and the last variable NEWER is Y if
A = 'NEW'


Below is my code but I can't get prxmatch() to work



DATA TEST; 
SET TEST.TEST;
if A = 'NO' and B = 'YES' and C = 'PRESENT' then NEW = 'Y';
else if B = 'NO' and C = 'MAYBE' then NEW = 'Y';
else if prxmatch('m/NO/FL|T2/FL/oi', C) > 0 and B = 'NO' then NEW = 'Y';
else NEW = 'N';
if A = 'NO' and B = 'NO' and E = 'Y' then NEXT = 'Y';
else NEXT = 'N';
if A = 'NEW' then NEWER = 'Y';
RUN;

PROC PRINT DATA = TEST;
RUN;









share|improve this question























  • You need to provide some sample data, so that someone can help you to understand why it is not working
    – Kiran
    Nov 13 '18 at 2:10










  • Is the information in the first code block actually textual data representing logic rules that need to be evaluated against the data ?
    – Richard
    Nov 13 '18 at 13:17













0












0








0







I would like to create new columns variable using criteria matched in prxmatch.



The first variable 'NEW' is Y if: 
a. (A= "YES", B="NO" and C="PRESENT") or
b. (B="NO" and C="MAYBE") or
c. (B="NO" and C in ("NO/FL", "T2/FL "))
else N
The second variable 'NEXT' is Y if:
A = 'NO' and B = 'NO' and E = 'Y'
else N
and the last variable NEWER is Y if
A = 'NEW'


Below is my code but I can't get prxmatch() to work



DATA TEST; 
SET TEST.TEST;
if A = 'NO' and B = 'YES' and C = 'PRESENT' then NEW = 'Y';
else if B = 'NO' and C = 'MAYBE' then NEW = 'Y';
else if prxmatch('m/NO/FL|T2/FL/oi', C) > 0 and B = 'NO' then NEW = 'Y';
else NEW = 'N';
if A = 'NO' and B = 'NO' and E = 'Y' then NEXT = 'Y';
else NEXT = 'N';
if A = 'NEW' then NEWER = 'Y';
RUN;

PROC PRINT DATA = TEST;
RUN;









share|improve this question















I would like to create new columns variable using criteria matched in prxmatch.



The first variable 'NEW' is Y if: 
a. (A= "YES", B="NO" and C="PRESENT") or
b. (B="NO" and C="MAYBE") or
c. (B="NO" and C in ("NO/FL", "T2/FL "))
else N
The second variable 'NEXT' is Y if:
A = 'NO' and B = 'NO' and E = 'Y'
else N
and the last variable NEWER is Y if
A = 'NEW'


Below is my code but I can't get prxmatch() to work



DATA TEST; 
SET TEST.TEST;
if A = 'NO' and B = 'YES' and C = 'PRESENT' then NEW = 'Y';
else if B = 'NO' and C = 'MAYBE' then NEW = 'Y';
else if prxmatch('m/NO/FL|T2/FL/oi', C) > 0 and B = 'NO' then NEW = 'Y';
else NEW = 'N';
if A = 'NO' and B = 'NO' and E = 'Y' then NEXT = 'Y';
else NEXT = 'N';
if A = 'NEW' then NEWER = 'Y';
RUN;

PROC PRINT DATA = TEST;
RUN;






sas






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 2:01









Kiran

2,5523819




2,5523819










asked Nov 13 '18 at 1:46









STL

1207




1207











  • You need to provide some sample data, so that someone can help you to understand why it is not working
    – Kiran
    Nov 13 '18 at 2:10










  • Is the information in the first code block actually textual data representing logic rules that need to be evaluated against the data ?
    – Richard
    Nov 13 '18 at 13:17
















  • You need to provide some sample data, so that someone can help you to understand why it is not working
    – Kiran
    Nov 13 '18 at 2:10










  • Is the information in the first code block actually textual data representing logic rules that need to be evaluated against the data ?
    – Richard
    Nov 13 '18 at 13:17















You need to provide some sample data, so that someone can help you to understand why it is not working
– Kiran
Nov 13 '18 at 2:10




You need to provide some sample data, so that someone can help you to understand why it is not working
– Kiran
Nov 13 '18 at 2:10












Is the information in the first code block actually textual data representing logic rules that need to be evaluated against the data ?
– Richard
Nov 13 '18 at 13:17




Is the information in the first code block actually textual data representing logic rules that need to be evaluated against the data ?
– Richard
Nov 13 '18 at 13:17












1 Answer
1






active

oldest

votes


















1














the code for prxmatch did not wotk becacuse you have / and / is used for start and end of regular expression and whenever you have NO/FL it error's out because it your regular expression feels that it came to end and when it few more words after / it fails, so you need to NO/FL as NO /FL, without space as shown in below code.



 data have;
input A $ B $ C $;
datalines;
NO YES PRESENT
NO NO MAYBE
NO NO NO/FL
YES NO T2/FL
;

DATA TEST;
SET have;
if A = 'NO' and B = 'YES' and C = 'PRESENT' then NEW = 'Y';
else if B = 'NO' and C = 'MAYBE' then NEW = 'Y';
else if prxmatch('m/NO/FL|T2/FL/oi', C) > 0 and B = 'NO' then NEW = 'Y';
else NEW = 'N';
RUN;

/* i would try something like below just for testing purpose to see how your code
works*/

DATA TEST;
SET have;
if A = 'NO' and B = 'YES' and C = 'PRESENT' then NEW = 'Yah';
else if B = 'NO' and C = 'MAYBE' then NEW = 'Yoh';
else if prxmatch('m/NO/FL|T2/FL/oi', C) > 0 and B = 'NO' then NEW = 'Yay';
else NEW = 'N';
RUN;





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%2f53272595%2fusing-sas-prxmatch-to-create-variable%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    the code for prxmatch did not wotk becacuse you have / and / is used for start and end of regular expression and whenever you have NO/FL it error's out because it your regular expression feels that it came to end and when it few more words after / it fails, so you need to NO/FL as NO /FL, without space as shown in below code.



     data have;
    input A $ B $ C $;
    datalines;
    NO YES PRESENT
    NO NO MAYBE
    NO NO NO/FL
    YES NO T2/FL
    ;

    DATA TEST;
    SET have;
    if A = 'NO' and B = 'YES' and C = 'PRESENT' then NEW = 'Y';
    else if B = 'NO' and C = 'MAYBE' then NEW = 'Y';
    else if prxmatch('m/NO/FL|T2/FL/oi', C) > 0 and B = 'NO' then NEW = 'Y';
    else NEW = 'N';
    RUN;

    /* i would try something like below just for testing purpose to see how your code
    works*/

    DATA TEST;
    SET have;
    if A = 'NO' and B = 'YES' and C = 'PRESENT' then NEW = 'Yah';
    else if B = 'NO' and C = 'MAYBE' then NEW = 'Yoh';
    else if prxmatch('m/NO/FL|T2/FL/oi', C) > 0 and B = 'NO' then NEW = 'Yay';
    else NEW = 'N';
    RUN;





    share|improve this answer



























      1














      the code for prxmatch did not wotk becacuse you have / and / is used for start and end of regular expression and whenever you have NO/FL it error's out because it your regular expression feels that it came to end and when it few more words after / it fails, so you need to NO/FL as NO /FL, without space as shown in below code.



       data have;
      input A $ B $ C $;
      datalines;
      NO YES PRESENT
      NO NO MAYBE
      NO NO NO/FL
      YES NO T2/FL
      ;

      DATA TEST;
      SET have;
      if A = 'NO' and B = 'YES' and C = 'PRESENT' then NEW = 'Y';
      else if B = 'NO' and C = 'MAYBE' then NEW = 'Y';
      else if prxmatch('m/NO/FL|T2/FL/oi', C) > 0 and B = 'NO' then NEW = 'Y';
      else NEW = 'N';
      RUN;

      /* i would try something like below just for testing purpose to see how your code
      works*/

      DATA TEST;
      SET have;
      if A = 'NO' and B = 'YES' and C = 'PRESENT' then NEW = 'Yah';
      else if B = 'NO' and C = 'MAYBE' then NEW = 'Yoh';
      else if prxmatch('m/NO/FL|T2/FL/oi', C) > 0 and B = 'NO' then NEW = 'Yay';
      else NEW = 'N';
      RUN;





      share|improve this answer

























        1












        1








        1






        the code for prxmatch did not wotk becacuse you have / and / is used for start and end of regular expression and whenever you have NO/FL it error's out because it your regular expression feels that it came to end and when it few more words after / it fails, so you need to NO/FL as NO /FL, without space as shown in below code.



         data have;
        input A $ B $ C $;
        datalines;
        NO YES PRESENT
        NO NO MAYBE
        NO NO NO/FL
        YES NO T2/FL
        ;

        DATA TEST;
        SET have;
        if A = 'NO' and B = 'YES' and C = 'PRESENT' then NEW = 'Y';
        else if B = 'NO' and C = 'MAYBE' then NEW = 'Y';
        else if prxmatch('m/NO/FL|T2/FL/oi', C) > 0 and B = 'NO' then NEW = 'Y';
        else NEW = 'N';
        RUN;

        /* i would try something like below just for testing purpose to see how your code
        works*/

        DATA TEST;
        SET have;
        if A = 'NO' and B = 'YES' and C = 'PRESENT' then NEW = 'Yah';
        else if B = 'NO' and C = 'MAYBE' then NEW = 'Yoh';
        else if prxmatch('m/NO/FL|T2/FL/oi', C) > 0 and B = 'NO' then NEW = 'Yay';
        else NEW = 'N';
        RUN;





        share|improve this answer














        the code for prxmatch did not wotk becacuse you have / and / is used for start and end of regular expression and whenever you have NO/FL it error's out because it your regular expression feels that it came to end and when it few more words after / it fails, so you need to NO/FL as NO /FL, without space as shown in below code.



         data have;
        input A $ B $ C $;
        datalines;
        NO YES PRESENT
        NO NO MAYBE
        NO NO NO/FL
        YES NO T2/FL
        ;

        DATA TEST;
        SET have;
        if A = 'NO' and B = 'YES' and C = 'PRESENT' then NEW = 'Y';
        else if B = 'NO' and C = 'MAYBE' then NEW = 'Y';
        else if prxmatch('m/NO/FL|T2/FL/oi', C) > 0 and B = 'NO' then NEW = 'Y';
        else NEW = 'N';
        RUN;

        /* i would try something like below just for testing purpose to see how your code
        works*/

        DATA TEST;
        SET have;
        if A = 'NO' and B = 'YES' and C = 'PRESENT' then NEW = 'Yah';
        else if B = 'NO' and C = 'MAYBE' then NEW = 'Yoh';
        else if prxmatch('m/NO/FL|T2/FL/oi', C) > 0 and B = 'NO' then NEW = 'Yay';
        else NEW = 'N';
        RUN;






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 13 '18 at 3:04

























        answered Nov 13 '18 at 2:27









        Kiran

        2,5523819




        2,5523819



























            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.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • 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%2f53272595%2fusing-sas-prxmatch-to-create-variable%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

            Top Tejano songwriter Luis Silva dead of heart attack at 64

            政党

            天津地下鉄3号線