BookmarkSubscribeRSS Feed
testlwc
SAS Employee

I'm dealing with disease data which has two variabes: GroupID and Infection_date. For example:

GroupIDInfection_date
A2014/01/03
A2014/02/10
A2014/03/05
B2014/01/01
B2014/02/01
B2014/03/15
B2014/03/15

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:

GroupIDFirstLast
A2014/01/032014/03/15
B2014/01/012014/03/15

I tried some different ways but none of them success. Dose any one have experience with this? Thanks a lot.

14 REPLIES 14
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

Variety of ways spring to mind, this would be my choice:

proc sql;

  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

  on      A.GROUPID=B.GROUPID;

quit;

Astounding
PROC Star

An easy way, assuming that DATE is actually numeric (SAS doesn't have a DATE type):

proc summary data=have nway;

   var infection_date;

   class groupID;

   output out=want (keep=groupID first last) min=first max=last;

run;

You might need to apply a format to FIRST and LAST to view them as dates.

Haikuo
Onyx | Level 15

Another SQL:

proc sql;

     create table WANT as

           select  GROUPID, MIN(INFECTION_DATE) as FIRST, MAX(INFECTION_DATE) as LAST

                FROM HAVE

                     GROUP BY GROUPID

     ;

quit;

Haikuo

testlwc
SAS Employee

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.

Allan_dk
Quartz | Level 8

Hi

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.

testlwc
SAS Employee

Thanks Allan

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.....

Allan_dk
Quartz | Level 8

Sorry, I forgot that you can't change format to date.

So, yes - you are stuck.  :smileycry:

SASKiwi
PROC Star

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?

testlwc
SAS Employee

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.Smiley Sad


SASKiwi
PROC Star

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.

testlwc
SAS Employee

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.

ted_werner_sas_com
SAS Employee

screenshot_865.png

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.

Regards,

Ted Werner

meimei
Calcite | Level 5

Hi Ted,

 

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?

 

Thanx!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

Tips for filtering data sources in SAS Visual Analytics

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.

Discussion stats
  • 14 replies
  • 10659 views
  • 0 likes
  • 8 in conversation