BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Laura1890
Calcite | Level 5

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;

1 ACCEPTED SOLUTION

Accepted Solutions
yabwon
Meteorite | Level 14

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



View solution in original post

5 REPLIES 5
SASJedi
SAS Super FREQ

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!

 

Check out my Jedi SAS Tricks for SAS Users
yabwon
Meteorite | Level 14

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



Laura1890
Calcite | Level 5

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"

yabwon
Meteorite | Level 14

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



Laura1890
Calcite | Level 5
Got it, didn't realize that & needs to be deleted.

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 472 views
  • 2 likes
  • 3 in conversation