BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
anshika
Fluorite | Level 6
How to report values of a variable from a dataset that are not present in another dataset
1 ACCEPTED SOLUTION

Accepted Solutions
8 REPLIES 8
anshika
Fluorite | Level 6
Data file1;
Set one;
Input prsnid $ ;
Datalines;
11
12
13
14; run;

Data file2;
Set two
Input prsnid $ gracedate yymmdd10.;
Datalines;
11 2020-12-31
12 2020-12-31
14 2020-01-01; run;

I need to report prsnid=13 in excel sheet because that is missing from second dataset
KathyKiraly
SAS Employee

This code will return 13, which is in file1, but not file2.

data file1;
  input prsnid $ ;
datalines;
11
12
13
14
; 
run;

data file2;
 input prsnid $ gracedate yymmdd10.;
datalines;
11 2020-12-31
12 2020-12-31
14 2020-01-01
; 
run;
proc sql;
  select prsnid
    from file1
  except 
  select prsnid
    from file2
;
quit;
anshika
Fluorite | Level 6
Yes this code worked. Thanks.
But can I use multiple datasets in place of File2?
Kurt_Bremser
Super User

You can have multiple hash objects in your data step. The limiting factor is the memory available vs. the size of the objects (variable(s) size * number of items + overhead for building the btree).

Each "lookup" dataset will have its own object with its own methods (f3.check(), f4.check(), and so on).

KathyKiraly
SAS Employee

If I understand your question, you can use the EXCEPT operator in PROC SQL. It will display values of a variable that are present in the first data set, but not in the second data set. Here is some code to test.

data one;
  input num;
cards;
1
2
3
4
;
run;
data two;
  input num;
cards;
1
2
6
7
;
run;
proc sql;
  select num
    from one
  except
  select num
    from two
;
quit;

The final result will display 3 and 4.

anshika
Fluorite | Level 6
Data file1;
Set one;
Input prsnid $ ;
Datalines;
11
12
13
14; run;

Data file2;
Set two
Input prsnid $ gracedate yymmdd10.;
Datalines;
11 2020-12-31
12 2020-12-31
14 2020-01-01; run;

I need to report prsnid=13 in excel sheet because that is missing from second dataset

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 8 replies
  • 2131 views
  • 2 likes
  • 3 in conversation