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. 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 10 replies
  • 2393 views
  • 0 likes
  • 4 in conversation