BookmarkSubscribeRSS Feed
ybz12003
Rhodochrosite | Level 12

I have a PROC FREQ code listed below in the frequency output dataset, CNT. I would like to obtain information for the latest collection date in the "Have" dataset. Is there a way to add a step in the PROC FREQ procedure, or do I need to add an extra data step and merge it with the output CNT data? Please help, thanks.

 

Proc freq data=Have noprint; 
	table  LabIDs*Test_Code*Match / nopercent nocol  out=CNT;
	where match in ('N');
run;
3 REPLIES 3
mkeintz
PROC Star

You do not provide enough information to answer your own question.

 

Mainly, what exactly do you mean by "collection date"?  Is it a variable in the dataset HAVE?  You specify three variables in HAVE (Labids, test_code, match), none of which suggest a collection date.

 

Is it the creation date of HAVE?

 

BTW, there is no need for the ** match" expression in the TABLE statement, since you allow only one match value,  i.e. where match in ('N').

 

Please clarify.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
ballardw
Super User

@ybz12003 wrote:

I have a PROC FREQ code listed below in the frequency output dataset, CNT. I would like to obtain information for the latest collection date in the "Have" dataset. Is there a way to add a step in the PROC FREQ procedure, or do I need to add an extra data step and merge it with the output CNT data? Please help, thanks.


You ask "for the latest collection date in the "Have" dataset" but your code is getting counts by LabIds and Test_code. So should that request be "for the latest collection date in the "Have" for each LabIds and Test_code combination in the dataset"? Quite a bit different things.

If you want latest date for each combination of LabIds and Test_code AND have a collection date variable one way AND that the sort order for the collection date variable sorts in date order (i.e and an actual SAS date value or a YYYYMMDD value) the following should work.

Proc freq data=Have noprint; 
	table  LabIDs*Test_Code*collectiondate*Match / nopercent nocol  out=CNT;
	where match in ('N');
run;

data want;
   set count;
   by Labids test_code;
   if last.test_code;l
run;

 

ybz12003
Rhodochrosite | Level 12

The Collection_Date volume (mmddyy10.) is in the "Have" dataset, but not in the CNT frequency output dataset.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 256 views
  • 0 likes
  • 3 in conversation