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
Yes
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 ;
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
By Michele Burlew
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.
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
@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! 😉
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.