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

This is what I want to accomplish:

Data Table_I_Want;

 

     set work.Source_Table;

     where MATERIAL_NUMBER in (

'1001'
'1002'
'1005'
'1011'
);
run;


I'd like to be able to accomplish this by referencing a table with a list of material numbers.  It does not need to be a WHERE IN statement.

 

Thanks!


1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

One way:

Data Table_I_Want;
     merge work.Source_Table
           reference_table (in=inreference)
     ;

     by MATERIAL_NUMBER;
     if inreference;
run;

The (in=inreference) creates a SAS temporary variable that is true/false or 1/0 when the current record has a contribution from that data set. This would require both data sets to be sorted by Material_number. Hopefully your reference_table, or what ever the name might be, does not have repeats of any Material_number values.

 

 

View solution in original post

3 REPLIES 3
ballardw
Super User

One way:

Data Table_I_Want;
     merge work.Source_Table
           reference_table (in=inreference)
     ;

     by MATERIAL_NUMBER;
     if inreference;
run;

The (in=inreference) creates a SAS temporary variable that is true/false or 1/0 when the current record has a contribution from that data set. This would require both data sets to be sorted by Material_number. Hopefully your reference_table, or what ever the name might be, does not have repeats of any Material_number values.

 

 

BarryP
Quartz | Level 8
Thanks. It's been months since I've touched SAS and wasn't sure how the merge would work. I didn't know if it would only give me 4 rows. Looks like it works as long as my material numbers are unique.
BarryP
Quartz | Level 8

Ok, I think I have it.  This is how I'm doing it:

 

Data Material_Num_Table;


     input @1 MATERIAL_NUMBER $54.;

     datalines;

1001

1002
1005

1011
;
run;

 

 

data Table_I_Want;

merge Material_Num_Table(in=InMat) Source_Table(;
by MATERIAL_NUMBER ;
if InMat;

run;

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
  • 3 replies
  • 1758 views
  • 1 like
  • 2 in conversation