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
Onyx | Level 15

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
Onyx | Level 15

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
Onyx | Level 15

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.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

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