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

Hello,

I have a set of time series of date data (see below). But the type of data is 'Numerical', the Format is 'Best12.' and informat is 12.''. When I use the code 'year(date)', I get wrong outcome. How to manipulate these date data if I want to get '1960 for year and 01 for month of first obs' using codes 'year(date) and month(date)'? Thanks

date

196001

196002

196003

196004

.....

.....

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

year=floor(date/100);

month=mod(date,100);

The YEAR and MONTH functions that you are trying to use only work on data stored as SAS dates, which these are not.

--
Paige Miller

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

year=floor(date/100);

month=mod(date,100);

The YEAR and MONTH functions that you are trying to use only work on data stored as SAS dates, which these are not.

--
Paige Miller
SASKiwi
PROC Star

If you want to make a SAS date from your date number first:

format sas_date date9.;

sas_date = input(date, yymmn6.);

year = year(sas_date);

month = month(sas_date);

naveen20jan
Obsidian | Level 7

Hi ,

We can also use the below approach .

data have ;

input date ;

year = input(substr(strip(date),1,4),6.);

month= input(substr(strip(date),5,2),4.);

datalines;

196001

196002

196003

196004

;

run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 987 views
  • 6 likes
  • 4 in conversation