Learning SAS? Welcome to the exclusive online community for all SAS learners.

Separating proc freq by dates

Reply
Frequent Contributor
Posts: 77

Separating proc freq by dates

 Hello,

 

I'm trying to set up a proc freq function where I am looking at counts of a certain screening done by location. In my dataset, I have a column called DCdeathdate which basically indicates what date the entry was stored and it is stored in this fashion "01/01/2017". My dataset spans 3 months (Nov, Dec, Jan). How do I generate a proc freq where I'd like to look at the number of counts by location in 3 different dates? I used this but it looks like its giving me every individual date that has shown up in the dataset. Thanks for your help!

 

proc freq data=mydata.inptdatamainfile order=freq;
tables dcdeathdate*_OrganizationName*hepcscreeningdone / nocol nopercent;
where _organizationregion='Adjara';
run;
Super Contributor
Posts: 251

Re: Separating proc freq by dates

Can you provide a little test data, and how you would like the output to look please? It'll make it much easier. Otherwise it's a bit guessworky.

Frequent Contributor
Posts: 77

Re: Separating proc freq by dates

sample1.png

 

I'd like to take something like this and make it into 3 different months (Nov, Dec, Jan)

Super Contributor
Posts: 251

Re: Separating proc freq by dates

Simply by using a format on dcdeathdate in your proc freq, the accumulation will be at the monthly level you require. I created some random data to show it:


data inptdatamainfile;
attrib dcdeathdate length=4 format=ddmmyy10.;
attrib _OrganizationName length=$ 30;
attrib hepcscreeningdone length=$ 3;
do i = 1 to 1000;
   dcdeathdate = (int(ranuni(0) * 120)) + ('1nov2016'd) + 1;
   hepcscreeningdone = ifc(ranuni(0) > .5, 'Yes', 'No');
   _OrganizationName = 'Organisation ' || byte(int(ranuni(0) * 4) + 1 + 64);
   output;
   end;
keep dcdeathdate _OrganizationName hepcscreeningdone;
run;

proc freq data=inptdatamainfile order=freq;
table dcdeathdate*_OrganizationName*hepcscreeningdone / nocol nopercent;
format dcdeathdate monyy7.;
run;
Super User
Posts: 6,936

Re: Separating proc freq by dates

To provide test data, use a data step as described here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Ask a Question
Discussion stats
  • 4 replies
  • 181 views
  • 0 likes
  • 3 in conversation