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.

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