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
/* 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;
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_IDThere 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.
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.
@KsharpThank you. It is working now. I truly appreciate your guidance.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.