BookmarkSubscribeRSS Feed
ogarduno
Obsidian | Level 7

Hi, I have a semester's worth of knowledge on SAS and picked up an internship at a state health department so my background in SAS needs a refresher. My first project is comparing the number of forms received this year (electronically received) to last years (received by mail). They would like for me to compare by week to week number of entries received for each year. The dates received have been put into excel by mm//dd/yyy. I have full flexibility for presentation so I was thinking of comparing the rates by numbers and visually with a histogram.

 

My question: How do I convert mm/dd/yyyy to a numerical variable and record the number of forms received weekly?

4 REPLIES 4
Reeza
Super User

You can find a lot of SAS tutorials here

http://video.sas.com/#category/videos/how-to-tutorials

 

Is your data already in SAS? If so, run a proc contents and post that and hightlight which variables are the ones that you need help with. 

Otherwise first get your data into SAS using PROC IMPORT.

 


@ogarduno wrote:

Hi, I have a semester's worth of knowledge on SAS and picked up an internship at a state health department so my background in SAS needs a refresher. My first project is comparing the number of forms received this year (electronically received) to last years (received by mail). They would like for me to compare by week to week number of entries received for each year. The dates received have been put into excel by mm//dd/yyy. I have full flexibility for presentation so I was thinking of comparing the rates by numbers and visually with a histogram.

 

My question: How do I convert mm/dd/yyyy to a numerical variable and record the number of forms received weekly?


 

ogarduno
Obsidian | Level 7

Thanks for the link! Definitely going to look in there. I think I figured out how to format my date correctly with:

 

data have;

informat date mmddyy10.;

format date mmddyy10.;

input date;

cards;

01/31/2012;

 

data want;

set have;

ndate=put(date,mmddyyn.);

proc print;run;

 

I think my question now is how can I create a visual aid for the number of entries by each week? My starting date is 06/01/2017 and I have to count the number of entries received by each week.

 

Reeza
Super User

Use PROC FREQ with a format for your date.

You can find the correct formats here:

proc freq data=have;
table date/out=want;
format date weeku3.;
run;

 


@ogarduno wrote:

Thanks for the link! Definitely going to look in there. I think I figured out how to format my date correctly with:

 

data have;

informat date mmddyy10.;

format date mmddyy10.;

input date;

cards;

01/31/2012;

 

data want;

set have;

ndate=put(date,mmddyyn.);

proc print;run;

 

I think my question now is how can I create a visual aid for the number of entries by each week? My starting date is 06/01/2017 and I have to count the number of entries received by each week.

 


 

ballardw
Super User

I agree with @Reeza that a format is the most likely way to group date items though SAS has not supplied a format that would include Year information and week in a nice form. But they allow you to create a custom format, something you may not have been exposed to previously, that allows providing a more flexible appearance. Here is an example showing Year and week of year combined.

Proc format library=work;
picture Yearwk  (default=7)
low-high = '%Y-%0W' (datatype=Date);
run;

data example;
   input dd mmddyy10.;
datalines;
01/05/2017
10/06/2016
07/21/2015
;
run;

proc print data=example;
   format dd YearWk.;
run;

The - in the low-high = '%Y-%0W' (datatype=Date) is there as a visual separator, any character could be used. The 0 is to have single digit weeks prefixed with a 0 sort could be maintained as needed. Note that documentation for Proc Format includes other directives, the funny %Y and %W bits. The case of the letters is important so pay attention.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1501 views
  • 5 likes
  • 3 in conversation