<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Hash Object Key Summary Variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Hash-Object-Key-Summary-Variable/m-p/864957#M341540</link>
    <description>&lt;P&gt;This is exactly what I needed. Thanks for sharing your expertise!&lt;/P&gt;</description>
    <pubDate>Fri, 17 Mar 2023 18:46:19 GMT</pubDate>
    <dc:creator>taishayla</dc:creator>
    <dc:date>2023-03-17T18:46:19Z</dc:date>
    <item>
      <title>Hash Object Key Summary Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-Object-Key-Summary-Variable/m-p/864601#M341431</link>
      <description>&lt;P&gt;Hello -&amp;nbsp;&lt;SPAN&gt;I am trying to use a hash object to create a key summary variable (totalsurveys). My goal is to get the total number of surveys completed for each client (see below table of what I'd like to achieve). My SAS code is as follows, but is not giving what I am looking for (help is appreciated!):&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data example; set example;&lt;BR /&gt;by participantid assessmentid datapointid;&lt;BR /&gt;*count=1;&lt;BR /&gt;if first.assessmentid and datapointid=1 then do;&lt;BR /&gt;count=1;&lt;BR /&gt;declare hash myhash(multidata: 'y',suminc: 'count');&lt;BR /&gt;myhash.definekey('participantid','first.assessmentid');&lt;BR /&gt;myhash.definedone();&lt;BR /&gt;myhash.add();&lt;BR /&gt;myhash.find();&lt;BR /&gt;myhash.sum(sum: totalsurveys);&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Goal:&lt;/P&gt;&lt;P&gt;ParticipantID AssessmentID DataPointID count totalsurveys&lt;BR /&gt;1 46974 572 1 1&lt;BR /&gt;1 46974 573 . .&lt;BR /&gt;1 46974 574 . .&lt;BR /&gt;1 574487 572 1 2&lt;BR /&gt;1 574487 573 . .&lt;BR /&gt;1 574487 574 . .&lt;BR /&gt;2 695197 572 1 1&lt;BR /&gt;2 695197 573 . .&lt;BR /&gt;2 695197 574 . .&lt;BR /&gt;3 695197 572 1 1&lt;BR /&gt;3 695197 573 . .&lt;BR /&gt;3 695197 574 . .&lt;BR /&gt;4 695197 572 1 1&lt;BR /&gt;4 1762071 573&lt;BR /&gt;4 1762071 574 . .&lt;BR /&gt;4 1762071 572 1 2&lt;BR /&gt;4 1762071 573 . .&lt;BR /&gt;4 1762071 574 . .&lt;/P&gt;</description>
      <pubDate>Thu, 16 Mar 2023 16:30:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-Object-Key-Summary-Variable/m-p/864601#M341431</guid>
      <dc:creator>taishayla</dc:creator>
      <dc:date>2023-03-16T16:30:17Z</dc:date>
    </item>
    <item>
      <title>Re: Hash Object Key Summary Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-Object-Key-Summary-Variable/m-p/864782#M341483</link>
      <description>&lt;P&gt;Not quite sure what you are trying to accomplish with the hash table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your input data looks like this (the original data was not sorted as assumed in the program)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;                                                                                                                              
  input                                                                                                                                 
ParticipantID AssessmentID DataPointID;                                                                                                 
cards;                                                                                                                                  
1 46974 572                                                                                                                             
1 46974 573                                                                                                                             
1 46974 574                                                                                                                             
1 574487 572                                                                                                                            
1 574487 573                                                                                                                            
1 574487 574                                                                                                                            
2 695197 572                                                                                                                            
2 695197 573                                                                                                                            
2 695197 574                                                                                                                            
3 695197 572                                                                                                                            
3 695197 573                                                                                                                            
3 695197 574                                                                                                                            
4 695197 572                                                                                                                            
4 695197 573                                                                                                                            
4 695197 574                                                                                                                            
4 1762071 572                                                                                                                           
4 1762071 573                                                                                                                           
4 1762071 574                                                                                                                           
;run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I think you can get the result you want like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data first;                                                                                                                             
  set have;                                                                                                                             
  by participantid assessmentid DataPointID;                                                                                            
  if first.assessmentid;                                                                                                                
  retain count 1;                                                                                                                       
  if first.participantid then                                                                                                           
    totalsurveys=1;                                                                                                                     
  else                                                                                                                                  
    totalsurveys+1;                                                                                                                     
run;                                                                                                                                    
                                                                                                                                        
data want;                                                                                                                              
  merge have first;                                                                                                                     
  by participantid assessmentid datapointid;                                                                                            
run;            
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Mar 2023 10:27:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-Object-Key-Summary-Variable/m-p/864782#M341483</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2023-03-17T10:27:49Z</dc:date>
    </item>
    <item>
      <title>Re: Hash Object Key Summary Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-Object-Key-Summary-Variable/m-p/864957#M341540</link>
      <description>&lt;P&gt;This is exactly what I needed. Thanks for sharing your expertise!&lt;/P&gt;</description>
      <pubDate>Fri, 17 Mar 2023 18:46:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-Object-Key-Summary-Variable/m-p/864957#M341540</guid>
      <dc:creator>taishayla</dc:creator>
      <dc:date>2023-03-17T18:46:19Z</dc:date>
    </item>
  </channel>
</rss>

