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

Hi Reeza,

 

My example is somewhat contrived so it can be clear, and sufficiently informative so that I can modify the code of the solution to fit what actually occurs.

 

Each question id actually has between 6 to 7 characters.

 

Regards

 

 

 

 

 

 

Reeza
Super User
So you have something similar to those numbers in the first row?
novinosrin
Tourmaline | Level 20

HI @ADouglas  Good afternoon, Please find the below modified code for the new updated source. It's 1:50 pm at Chicago right now. I haven't tested "extensively" as I managed to sneak peek on SAS communities during a break. However, I will later tonight if I can after my case study submission if I have time. I might grab a couple of pints on my way home :), so do expect some delays should you require any further changes lol 

Have a good one!

 

/*New updated source from ADouglas*/
data have;
input A1 A2 A3 A4 B5 B6 C7 C8 C9;
cards;
1  0 1  0 1 0  1 0  1 
0  1 1  1 0 0  1 1  0 
1  1 1  1 0 0  0 0  1 
;
dm log 'clear';
/*Modified code to handle varying series of vars*/
data _null_ ;
  if _n_ = 1 then do ;
    declare hash h ;   
    declare hash hoh() ;  
    hoh.defineKey ("j") ;
    hoh.defineData ("h", "j") ;
	hoh.defineDone () ;
	end ;
set have end = lr ;  
array t(*) a1--c9;
do i= 1 to dim(t);
  j=first(vname(t(i)));
  if  hoh.find() ne 0 then 
		do ;  
   			 h = _new_ hash (multidata:"Y",ordered:'y') ;  
			 h.defineKey ('_n_') ; 
			 do k=i by 1 while(first(vname(t(k)))=j and k<=dim(t));
			 	if first(vname(t(i)))=j then h.defineData (vname(t(k))) ;
				if k=dim(t) then  leave;
			 end;
			h.defineDone () ;
		    hoh.add() ; 
			h.add() ;  
	   end; 
	else  h.replace() ;  
end;
if lr ;
  declare hiter ihoh ("hoh") ;  
  do while (ihoh.next() = 0) ;
     h.output (dataset:j) ;
  end ;
run ;

 

 

ADouglas
Obsidian | Level 7

Bravo Novinosrin!!

 

This code is more general. 

 

Other than the hard coding required for the input command (which I won't need to use because of PROC IMPORT), the only additional hard coding is the need to specify the last variable in the data set for the first array statement.

 

I never used hashing before. Can you recommend a good reading source about hashing?

 

Regards

novinosrin
Tourmaline | Level 20

SAS Hash Object Programming Made Easy

By Michele Burlew

 

Data Management Solutions Using SAS® Hash Table Operations: A Business Intelligence Case Study 

By Paul Dorfman and Don Henderson  - /* this is my favorite*/


Paul D is my guru. Plus for whatever reason and I don't know why i am so lucky, Paul D does help me out on a personal level. He believes I should go a long way and I hope those words come true someday.

 

 

ADouglas
Obsidian | Level 7

Thanks!!

 

This helps a bunch. I have a number of Cody's and Carpenter's books, and I find white papers through google searches. 

 

I always find a solution to a task. You should do very well. 

 

Keep it up!!

 

Regards

 

 

Reeza
Super User

@novinosrin wrote:

Just  a one caveat, I do have a presentation on a case study tomorrow that I hope to pass as I haven't even started yet lol, so the timing of my response may not be consistent. 

 @novinosrin Get off of here and go do your homework! 😉

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 22 replies
  • 1682 views
  • 10 likes
  • 4 in conversation