BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SigmaDawg
Calcite | Level 5

I have imported some data into SAS from some Excel spreadsheets sent to me. When I view the output from the imported table, the date appears as "01APR2014" and maintains chronological order. When I view the column properties the type is "Date" and the length is 8. Both the format and informat are DATE9. I need to be able to convert this date to week-year and month-year, but no matter what I try I always get Jan, 1960.

Using proc sql, I used the below to get the week-year:

"(put(datepart(a.fnlz_date),weeku3.))|| "-" ||(put(datepart(a.fnlz_date),year.)) as FNLZD_WK_YR,"

but all I got was "W00-1960". I've used the formula above successfully many times before with SAS datetime values.

For month-yr, using proc sql, I tried:

"datepart(a.fnlz_date) as DT_FNLZD format=monyy.,"

but the only value returned is "JAN60".

I also tried using SUBSTR, but got an error saying it requires a character argument, so SAS must see it as a number at least.

My question; does anyone know a way to get the week-yr and/or month-yr from this format? If so, how? I'm not opposed to using a data step, but I haven't been able to get that to work, either.

Thanks in advance for any help or insight provided.

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

Your data is already into a date format. The DATEPART function is for converting DATETIME values (numbers of seconds since 01JAN1960) into DATE (number of days since 01JAN1960). Using DATEPART on DATEs will divide the number of days by 86400 and bring your values very near 01JAN1960.

Just drop the DATEPART function and associate appropriate formats such as weeku5. or MONYY7, with your variables.

PG

PG

View solution in original post

4 REPLIES 4
Reeza
Super User

There is no TYPE=Date, only text and number. Which is yours?

Why are you using datepart, if it is a date, datepart is for datetime variables? Try removing the datepart and see if that works.

PGStats
Opal | Level 21

Your data is already into a date format. The DATEPART function is for converting DATETIME values (numbers of seconds since 01JAN1960) into DATE (number of days since 01JAN1960). Using DATEPART on DATEs will divide the number of days by 86400 and bring your values very near 01JAN1960.

Just drop the DATEPART function and associate appropriate formats such as weeku5. or MONYY7, with your variables.

PG

PG
Reeza
Super User

Also, my dogs name is Sigma :smileygrin:

SigmaDawg
Calcite | Level 5

Thanks for the help! Got it working, now.

Cheers!

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 4 replies
  • 6230 views
  • 5 likes
  • 3 in conversation