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;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.