BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
LNEW
Obsidian | Level 7

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;

1 ACCEPTED SOLUTION

Accepted Solutions
LNEW
Obsidian | Level 7
Our client requested datasets of each school. I have exported the data from REDCap into SAS. I was able to find my way ... and now have good results.
DATA _NULL_;
if _n_ = 1 then do;
if 0 then set redcap2;
declare hash eachschool (dataset: 'redcap2(obs = 0)' , multidata: 'y');
eachschool.definekey (all: 'yes');
eachschool.definedata (all: 'YES');
eachschool.definedone ();
end;

do until (last.pc);
set redcap2;
by pc cn;
eachschool.add();
end;
eachschool.output (dataset: compress ('PCSample'||pc));
eachschool.clear();
run;

View solution in original post

3 REPLIES 3
ballardw
Super User

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
Obsidian | Level 7
Our client requested datasets of each school. I have exported the data from REDCap into SAS. I was able to find my way ... and now have good results.
DATA _NULL_;
if _n_ = 1 then do;
if 0 then set redcap2;
declare hash eachschool (dataset: 'redcap2(obs = 0)' , multidata: 'y');
eachschool.definekey (all: 'yes');
eachschool.definedata (all: 'YES');
eachschool.definedone ();
end;

do until (last.pc);
set redcap2;
by pc cn;
eachschool.add();
end;
eachschool.output (dataset: compress ('PCSample'||pc));
eachschool.clear();
run;
PeterClemmensen
Tourmaline | Level 20

@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;

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1036 views
  • 0 likes
  • 3 in conversation