BookmarkSubscribeRSS Feed
Ksharp
Super User

I guess your VAR1 is numeric. And it has some decimal number.
Use the PUT() to see how many decimal do you have for this special number.

data _null_;
 set sashelp.class;
 x=put(height,32.10);
 put x=;
run;
11   data _null_;
12    set sashelp.class;
13    x=put(height,32.10);
14    put x=;
15   run;

x=69.0000000000
x=56.5000000000
x=65.3000000000
x=62.8000000000
x=63.5000000000
x=57.3000000000
x=59.8000000000
x=62.5000000000
x=62.5000000000
x=59.0000000000
x=51.3000000000
x=64.3000000000
x=56.3000000000
x=66.5000000000
Ksharp
Super User
/* Step 1: Create SET1 */
data SET1;
infile cards truncover;
    input ID Var1 P1 $ P2 P3 P4 P5;
    datalines;
1 3456
2 8796
3 2222
4 7689
;
run;

/* Step 2: Create SET2 */
data SET2;
infile cards truncover;
    input record_ID VAR1 B1 B2 B3 $ B4 B5;
    datalines;
10 3456
12 8796
15 2222
20 7689
;
run;

data want;
 if _n_=1 then do;
   if 0 then set set1;
   declare hash h(dataset:'set1');
   h.definekey('var1');
   h.definedata('id','P1', 'P2', 'P3', 'P4', 'P5');
   h.definedone();
 end;
set set2;
call missing(id);
rc=h.find();
drop rc record_ID;
run;
Mscarboncopy
Pyrite | Level 9

Thank you @Ksharp 

This is exactly what I needed.

I have a file "want" with only one record per id. All variables are in there (except the one I wanted to get rid of, after matching which is great)

record_ID

There is only one issue, for some reason all variables from set 1  have missing values, including id.

I added all the variables here as indicated:

  h.definedata('id','P1', 'P2', 'P3', 'P4', 'P5');

Not sure what to do to make sure the values are not turned into missing.

 

 

Ksharp
Super User

Sorry. My code is not right. Try this one :

 

data set1 ;
  input ID Var1 $ P1 $ P2 P3 P4 P5;
datalines;
1 3456 A 2 3 4 5
2 8796 B 1 2 2 4
3 2222 C 5 6 7 8
4 7689 D 9 1 2 3
;


data set2;
  input record_ID VAR1 $ B1 B2 B3 $ B4 B5;
datalines;
10 3456 1 2 A 3 4
12 8796 5 6 B 7 8
15 2222 9 1 C 2 3
20 7689 4 5 D 6 7
;

data want;
 if _n_=1 then do;
   if 0 then set set1;
   declare hash h(dataset:'set1');
   h.definekey('var1');
   h.definedata('id','P1', 'P2', 'P3', 'P4', 'P5');
   h.definedone();
 end;
set set2;
call missing(id,P1,P2,P3,P4,P5);
rc=h.find();
drop rc ;
run;

If you want drop some variable ,just list it under DROP statement;

drop rc Record_ID;

 

"There is only one issue, for some reason all variables from set 1  have missing values, including id."

That is because some VAR1 is NOT in set1 ,but in set2 . There is not a matching record.

Mscarboncopy
Pyrite | Level 9

@KsharpThank you. It is working now. I truly appreciate your guidance.

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
  • 19 replies
  • 2659 views
  • 4 likes
  • 4 in conversation