BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
tpchaudhary
Fluorite | Level 6

Hi There,

In below example, I would like to get missing ID values which is not matched with my assigned value in macro variable. I know I can perform this task as I did in my Query2 to get correct output, but I don't understand about what's wrong in my Query1.

Can someone explain me why query1 in my below piece of code is not giving desired output? 

/****************************************************************************************/

data ID_Table;
input ID $10.;
cards;
1000000001
1000000002
1000000003
;run;

%let IDN1 = 1000000001;
%let IDN2 = 1000000002;

/*Query1*/
data Missing_ID_Wrong_Output;
set ID_Table;
IDN1=input(&IDN1.,best12.);
IDN2=input(&IDN2.,best12.);
if (ID ne IDN1 OR ID ne IDN2) then output;
keep ID;
run;
proc print data=Missing_ID_Wrong_Output noobs;run;
/*
ID
1000000001
1000000002
1000000003
*/

/*Query2*/
data Missing_ID_Correct_Output;
set ID_Table;
if ID not in (&IDN1., &IDN2.) then output;
run;
proc print data=Missing_ID_Correct_Output noobs;run;
/*
ID
1000000003
*/

/****************************************************************************************/

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star
As was suggested, you need to change OR to AND. however, there is also another issue. You have ignored messages in the log about numeric to character conversion when using the INPUT function. The best solution would eliminate the INPUT function entirely.

if ID ne &IDN1 and ID ne &IDN2 then output;

View solution in original post

3 REPLIES 3
japelin
Rhodochrosite | Level 12

If fix below, you can get correct output.

 

if (ID ne IDN1 AND ID ne IDN2) then output;

Astounding
PROC Star
As was suggested, you need to change OR to AND. however, there is also another issue. You have ignored messages in the log about numeric to character conversion when using the INPUT function. The best solution would eliminate the INPUT function entirely.

if ID ne &IDN1 and ID ne &IDN2 then output;
tpchaudhary
Fluorite | Level 6

Thanks folks for quick respond with perfect solution!

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 3 replies
  • 776 views
  • 2 likes
  • 3 in conversation