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

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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