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.
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
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.
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.
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.
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.....
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.
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.
See how to use one filter for multiple data sources by mapping your data from SAS’ Alexandria McCall.
Find more tutorials on the SAS Users YouTube channel.