BookmarkSubscribeRSS Feed
deep3
Fluorite | Level 6

Hi Please help my query.

I am using SAS studio. I have been trying to find a serial number match between two table and update the values of the numbers that match in a new column

Table1:

ser_no x1 x2..

 

Table2 

ser_num x3 x4..

 

If the ser_no from table1 is present in table 2 (ser_num column) then fill the same value in a new column 'Comparison' in Table 1.

This is equivalent to =VLOOKUP(G1,$J:$J,1,0) G is ser_no (table1) J is ser_num from table2

 

I tried creating the entire column of table 2 in a macro variable.But nothing seems to work.

 

error.jpg

data testing;
 if _n_ eq 1 then do;
  if 0 then set table2;
  declare hash h(dataset:'table2');
  h.definekey('x3','x4');
  h.definedata('ser_num');
  h.definedone();
 end;
set table1;

run;
1 REPLY 1
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Please show test data, in the form of a datastep.  It is not possible to diagnose a problem with a data based programming language without seeing data.  At a rough guess, I would just merge the two datasets together e.g.

data want;
  set have1 have2;
  by idvar;
  combined_var=coalsecec(varfromhave1,varfromhave2);
run;

There are a lot of assumptions in there, both sorted by idvar, both has idvar, etc.  Again, without seeing data I couldn't possibly guess what you have.

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
  • 1 reply
  • 1335 views
  • 0 likes
  • 2 in conversation