08-28-2014 09:24 AM
I'm dealing with disease data which has two variabes: GroupID and Infection_date. For example:
Role type of GroupID is category and role type of Infection_date is date.
Now, I want to create a table contains the first infection date and last infection date for each GroupID like below:
I tried some different ways but none of them success. Dose any one have experience with this? Thanks a lot.
08-28-2014 09:31 AM
Variety of ways spring to mind, this would be my choice:
create table WANT as
select COALESCE(A.GROUPID,B.GROUPID) as GROUPID,
A.INFECTION_DATE as FIRST,
B.INFECTION_DATE as LAST
from (select GROUPID,MIN(INFECTION_DATE) as INFECTION_DATE from HAVE group by GROUPID) A
full join (select GROUPID,MAX(INFECTION_DATE) as INFECTION_DATE from HAVE group by GROUPID) B
08-28-2014 09:36 AM
An easy way, assuming that DATE is actually numeric (SAS doesn't have a DATE type):
proc summary data=have nway;
output out=want (keep=groupID first last) min=first max=last;
You might need to apply a format to FIRST and LAST to view them as dates.
08-28-2014 09:56 AM
create table WANT as
select GROUPID, MIN(INFECTION_DATE) as FIRST, MAX(INFECTION_DATE) as LAST
GROUP BY GROUPID
08-28-2014 10:19 AM
Thanks for all of your replies!
I forgot to mention that my platform is SAS Visual Analytics. So what I actually need is to build a "Report" in SAS VA 6.4 without any coding. All your suggestion are good on BASE SAS but not what I need. Thanks for your help again.
08-28-2014 12:28 PM
You just have to duplicate the date variable and rename it first date. Then change the aggregation to minimum.
The same goes for last date.
But you cant use the variable in filters.
BTW: There are a lot of helpful people in here, but they never notice that it is Visual Analytics forum, and always come up with answers in BASE SAS.
08-28-2014 01:39 PM
I've tried your method earlier, but only measure have aggregation option, date type variable doesn't.
Another method I'd try is use "TreatAs" operator to create new variable from Infection_date. This can correctly change date variable into measure. But it comes up another two problem:
1. I can't create max or min for each group. Aggregation work only when we use object with group role, but object "Table" doesn't have this concept.
2. Even if we create min and max successfully. Since these two variables are measure, we can't give them any date-like format.
then I stuck.....
09-02-2014 01:50 AM
How did you get your data into VA in the first place? Can you derive what you need outside of VA and re-import it?
09-02-2014 02:08 AM
Our raw data is a sas dataset and store infection_date as numeric variable with yymmdd10. format.
VA will auto change numeric variable with date-like format into "date" category.
So make some change before import data can't solve it as I know.
09-03-2014 06:06 PM
I was thinking along the lines of importing into VA the maximum and minimum dates for each group as described above. Would that help you with your issue? You should at least be able to filter on these.
09-04-2014 09:15 PM
Thanks Kiwi. It seems we can only use this preprocess method to achieve our goal. But this method against the spirit of VA, so we still looking for a better way.
09-08-2014 02:30 PM
In Version Visual Analytics 7.1, You will be able to use first and last function as part of the calculation editor. This will be in Designer and Explorer. You must have a by group otherwise it would have been a default aggregation. Look for Visual Analytics 7.1 to release in October. This will be in the calculation editor with more aggregated values as well. More details to come.
08-08-2016 10:50 AM
We're now using 7.3 and I'm still trying to solve this puzzle. Am I doing something wrong or is it still not possible?