I have a data set with a survey_identifier (school/class) which looks like 1_1_ for school 1, class 1 in which there will be many students. And I will have numerous schools with many class numbers. So for instance I will have 25 rows with 1_1_ because 25 students will be in that class. I am trying to use a Hash procedure to create separate data sets for each school but am getting an error "Uninitialized object at line 1030 column 16." Can someone help me figure out the issue. I have
DATA _NULL_;
declare hash eachschool (dataset: 'redcap1', ordered: 'Y');
eachschool.definekey ('redcap_survey_identifier', 'cn');
eachschool.definedata (all: 'YES');
eachschool.definedone ();
declare hiter heach ('eachschool');
declare hash hashnum;
do until (done);
set redcap1 end = done;
if eachschool.check () then do;
hashnum = _new_ hash (ordered: "Y");
hashnum.definekey ('redcap_survey_identifier', 'cn');
hashnum.definedata (all: "YES");
hashnum.definedone ();
rc = eachschool.replace();
end;
rc=eachschool.find();
rc=hashnum.replace(); /*THIS IS THE LINE GIVING ME THE ERROR*/
end;
do while (heach.next() = 0);
rc= hashnum.output (dataset: "school"||redcap_survey_identifier);
end;
stop; run;
Before going to a lot of headaches, why are you creating multiple data sets in the first place?
And with "redcap" in the code is the data actually a SAS data set already or still in a different database?
Please, when referencing error or warning messages, include the LOG of the code with the entire data step or procedure that is throwing the error including all the messages and notes. Copy the text from the log and paste into a text box opened on the forum with the </> icon to preserve the text formatting.
@LNEW glad you found your answer 🙂
One little thing. The DefineData Method call and If 0 then set Statement are obsolete here.
See this
proc sort data = sashelp.iris out=SortIris;
by species;
run;
data _null_;
if _N_ = 1 then do;
declare hash h(dataset:"SortIris(obs=0)", multidata:'y');
h.definekey(all:'y');
h.definedone();
end;
do until(last.species);
set SortIris;
by species;
h.add();
end;
h.output(dataset:species);
h.clear();
run;
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.