🔒 This topic is solved and locked.
Need further help from the community? Please
sign in and ask a new question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 04-10-2019 07:17 PM
(17777 views)
All,
I have a simple question. How can one perform a logical test to validate if a macro variable has missing value ?
For e.g.:
%Let a = .;
%Put &a.; %If &a = %str() %Then %Do;%Put "1";%End;
I thought something like this, but doesn't get me too far.
1 ACCEPTED SOLUTION
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
That's for a nonnull value. For a null value:
%if %length(&a)=0 %then %do;
%if %length(&a)=0 %then %do;
6 REPLIES 6
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
There are several ways, and an entire paper has been published on the subject. My favorite way:
%if %length(&a) %then %do;
%if %length(&a) %then %do;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
That's for a nonnull value. For a null value:
%if %length(&a)=0 %then %do;
%if %length(&a)=0 %then %do;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@Astounding ,
Thank you for your response. May I ask you to offer a little more clarity ,
%Let a = . ;
%if %length(&a) %then
%do;
%put 1;
%end;
%else;
%put 0;
%end;
This returns an error. Can you point as to what is wrong ? Additionally, can you point me to the paper you are referring to ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@UdayGuntupalli wrote:
(...) Additionally, can you point me to the paper you are referring to ?
Just for completeness, this is (most likely) the paper Astounding referred to: https://support.sas.com/resources/papers/proceedings09/022-2009.pdf
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
In macro language . is a character and not a missing value.
This statement is incorrect:
%else;
It should be:
%else %do;
Authors of the paper are Chung and King. For me, it's too difficult to find and post links using a mobile phone.
This statement is incorrect:
%else;
It should be:
%else %do;
Authors of the paper are Chung and King. For me, it's too difficult to find and post links using a mobile phone.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
%If &a = %Then %Do;%Put "1";%End;