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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.