Hello, I'm trying to use a hash table and/or dow loops to concatenate values by rows of data representing separate dates a color was added to the database. First I created a counter to determine the number of days between the dates the same color was added. I need this later on so I do not concatenate if the number of days is greater than 30. Also another rule for contentation is that the colors need to be entered on the same day. I grouped by date which worked for the matched dates but I also need the dates to repeat until the next match. Below I tried to create a sample dataset but had trouble with inputting dates (as usual) so if anyone can fix the input statement for the sample to work that would be great. The last variable, ExpectedCombo is what I want to end up with. The code I started with concatenates only the matched dates but needs to continue in other dates. Can any one help me create code to match the "expectedCombo" field? data have ; infile datalines dsd ; input id date MMDDYY10. color $10. expectedCombo $400.; datalines ; 1321,07/10/2015,blue,blue 1321,07/11/2015,blue,blue 1321,07/12/2015,blue,blue 1321,07/13/2015,blue,blue 1321,08/18/2015,red,blue - red 1321,08/19/2015,blue,blue - red 1321,08/20/2015,blue,blue - red 1321,08/21/2015,blue,blue - red 1321,08/22/2015,blue,blue - red 1321,09/15/2015,red,blue - red 1321,09/16/2015,blue,blue - red 1321,09/17/2015,blue,blue - red 1321,09/18/2015,blue,blue - red 1321,01/12/2016,red,blue - red 1321,01/12/2016,blue,blue - red 1321,01/13/2016,blue,blue - red 1321,01/14/2016,blue,blue - red 1321,01/15/2016,blue,blue - red 1321,01/16/2016,blue,blue - red 1321,01/17/2016,blue,blue - red 1321,01/18/2016,blue,blue - red 1321,01/19/2016,green,blue - red - green 1321,01/19/2016,blue,blue - red - green 1321,01/20/2016,blue,blue - red - green 1321,01/21/2016,blue,blue - red - green 1321,01/22/2016,blue,blue - red - green 1321,01/23/2016,blue,blue - red - green 1321,01/24/2016,blue,blue - red - green 1321,01/25/2016,blue,blue - red - green ; run; proc sort data=have ; by id date ; run; data revised1 ; set have ; by id date; format redStart greenStart date9. redInterval greenInterval 8. ; retain redStart greenStart redcounter 0 greencounter 0 redinterval greeninterval; if color='red' then do ; if redcounter>0 then redInterval=date - redStart ; redStart=date ; redcounter+1 ; end ; if color='green' then do ; if greencounter>0 then greenInterval=date - greenStart ; greenStart=date ; greencounter+1 ; end ; if last.id then do ; redStart=. ; greenStart=. ; end; redInterval=redInterval ; greenInterval=greenInterval ; run; proc print; run; PROC SORT DATA=REVISED1 ; BY ID Date ; RUN; data revised2 ; length newCombo $400 ; do until (last.date) ; set revised1 ; by id date ; if newCombo="" then newCombo=color; else newCombo = Catx(" - ",newcombo, color) ; end; do until (last.date) ; set revised1 ; by id date ; output; end; run; proc print; run;
... View more