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

Hi all,

 

I need help here.

 

I have two data set below

Capture.JPG

 

how can i get a result only showing Orange, Melon on the list.

I would to filter out common factors of Apple and Melon on the new list.

 

Thanks in advance

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

Test:

 

data table1;

input var $10.;

cards;
apple
pear
orange 
melon
;

 

data table2;

input var $10.;

cards;
apple
 melon
;


proc sql;
  create table want as
   select * from table1
   except
   select * from table2;
   quit;

proc print nobs;run;

RESULTS:

 

SAS Output

var
orange
pear

View solution in original post

10 REPLIES 10
novinosrin
Tourmaline | Level 20
proc sql;
  
   select * from table1
   except
   select * from table2;

assuming I understand your requirement 

miss2223
Fluorite | Level 6
Thanks for quick response.

It caused error message "180-322: Statement is not valid or it is used out
of proper order." which is underlined statement of except
novinosrin
Tourmaline | Level 20

Please post the sample of your datasets as plain text rather than pics and also post the output sample you want. Would be convenient if you could provide a good representative sample

miss2223
Fluorite | Level 6
Thanks for your recommendation. As I am new to the communities, good to
receive some positive feedback. 🙂

Table 1 Table 2
Apple Apple
Pear Melon
Orange
Melon

novinosrin
Tourmaline | Level 20

should i assume

 

data table1;

input var $10.;

cards;

apple

pear

orange 

melon

;

 

data table2;

input var $10.;

cards;

apple

 melon

;

 

and your required output is

data want;

input var $10.;

cards;

pear

orange 

;

 

?

 

miss2223
Fluorite | Level 6

Yes require output to appear "pear and orange in the list"

 

data want;

input var $10.;

cards;

pear

orange 

;

novinosrin
Tourmaline | Level 20

Test:

 

data table1;

input var $10.;

cards;
apple
pear
orange 
melon
;

 

data table2;

input var $10.;

cards;
apple
 melon
;


proc sql;
  create table want as
   select * from table1
   except
   select * from table2;
   quit;

proc print nobs;run;

RESULTS:

 

SAS Output

var
orange
pear
miss2223
Fluorite | Level 6
Got it! thanks for your patience
Kurt_Bremser
Super User

@miss2223 wrote:
Thanks for quick response.

It caused error message "180-322: Statement is not valid or it is used out
of proper order." which is underlined statement of except

You alread got lesson #1 for successful questions from @novinosrin (post example data in data steps with datalines)

Lesson #2:

When encountering an ERROR (or another message you do not understand), always post the whole log of the failing step into a window opened with the {i} button. The message alone does not tell us much, its positioning in relation to the code (and the code itself, of course) is important. Since the main posting window scrambles the formatting (by removing blanks), using the {i} is mandatory.

ballardw
Super User

@miss2223 wrote:
Thanks for quick response.

It caused error message "180-322: Statement is not valid or it is used out
of proper order." which is underlined statement of except

Sounds like you may have a ; at the end of the first part of:  select * from table ;

If so remove it. SQL script bits use one ; to end the whole statement which can have many parts. 

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 10 replies
  • 1563 views
  • 0 likes
  • 4 in conversation