Hello!
How to use hash object inside proc DS2, this code porduces Error:
proc ds2;
data cars_test_two / overwrite=yes;
/* Variable declarations */
declare char(13) Make;
declare char(8) Type; /* Adjusted length based on 'Sedan' */
declare int _rc;
/* Declare the hash object */
declare package.hash codes();
_rc = codes.defineKey('Make', 'Type');
_rc = codes.defineDone();
/* Load codes into hash object */
method init();
Make = 'Akura';
Type = 'Sedan';
_rc = codes.add();
Make = 'Audi';
Type = 'Sedan';
_rc = codes.add();
end;
method run();
set sashelp.cars (drop = DriveTrain);
if codes.check() = 0 then
output;
end;
enddata;
run;
quit;Hello @JanKwiatkowski,
I am a beginner when it comes to PROC DS2, but after fixing seven errors indicated in the logs (one per run) the code worked.
/* Declare the hash object */
declare package hash codes();
method init();
codes.defineKey('Make');
codes.defineKey('Type');
codes.defineDone();
set cars (drop = (DriveTrain));
data cars_test_two (drop = (rc)) / overwrite=yes;
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.