- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello community,
I am desperately trying to set up an IF/ELSE where the if-condition is based on a string comparison. If the variable is not equal to PRODET (I also tried 'PRODET') I want the macro to be executed. This is what looked pretty reasonable to me, but we tried various options.
DATA _NULL_;
IF (&v_modul_akt. NE PRODET)
THEN CALL EXECUTE ('%set_module_view');
RUN;
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I would even go 1 step further and do:
DATA _NULL_;
IF symget("v_modul_akt") NE "PRODET")
THEN CALL EXECUTE ('%set_module_view');
RUN;
to ensure that "strange" value of v_modul_akt won't blow up my sas 🙂
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug
"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings
SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Text without quotes around it is interpreted as code. So in your program, both the text resolved from &v_module_akt. an the word PRODET are both interpreted as variable names:
DATA _NULL_;
IF (&v_modul_akt. NE PRODET)
THEN CALL EXECUTE ('%set_module_view');
RUN;
Sinc nothing in the program assigns a value to those variables, they are both missing, so the values are equal. In your log you should see a NOTE indicating that the variables are uninitialized.
Try this instead:
DATA _NULL_;
IF ("&v_modul_akt." NE "PRODET")
THEN CALL EXECUTE ('%set_module_view');
RUN;
And may the SAS be with you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I would even go 1 step further and do:
DATA _NULL_;
IF symget("v_modul_akt") NE "PRODET")
THEN CALL EXECUTE ('%set_module_view');
RUN;
to ensure that "strange" value of v_modul_akt won't blow up my sas 🙂
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug
"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings
SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the help!
Unfortunately, I still struggle:
%LET v_modul_akt = PRODET;
DATA _NULL_;
IF (symget("&v_modul_akt.") NE "PRODET")
THEN CALL EXECUTE ('%set_module_view');
RUN;
This snippet still calls the macro, even though the if-statement says "PRODET" NE "PRODET"
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Read the code I typed...
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug
"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings
SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content