BookmarkSubscribeRSS Feed
dennis_e
Fluorite | Level 6

Is there an easy way to convert a combined year and month value to a SAS DATE?

 

I have the following data, and wanted to use some of the SAS Time Series methods

 

There is a number for year, but it also has a two digit number for month combined. The data are in an Excel format.

 

Here is asample of the data:

 

The first variable is January in the year 1895. PCP is the total precipitation for that month.

 

YearMonth      PCP

189501           6.89

189502           2.94

189503           5.66

 

 

The data go up to December 2017.

 

I would like to be able to total up all the PCP for a year, plot it -- then plot the next year’s total PCP, etc all the way up to 2017.

 

5 REPLIES 5
novinosrin
Tourmaline | Level 20

may this demo help?  Mind you! ---The sasdate value will revert to first of the month though

data have;
input YearMonth      PCP;
cards;
189501           6.89
189502           2.94
189503           5.66
;

data want;
set have;
k=put(YearMonth,8. -l);
sasdate=input(k,yymmn6.);
format sasdate date9.;
run;

 

 

novinosrin
Tourmaline | Level 20

or just:

data have;
input YearMonth      PCP;
cards;
189501           6.89
189502           2.94
189503           5.66
;

data want;
set have;
sasdate=input(put(YearMonth,8. -l),yymmn6.);
format sasdate date9.;
run;
dennis_e
Fluorite | Level 6
Thank you -- Can't wait to try this later.
PGStats
Opal | Level 21

If yearMonth is a number then convert to a SAS date with

 

ymDT = mdy(mod(YearMonth,100), 1, int(YearMonth/100));
format ymDT yymmd.;

PG
dennis_e
Fluorite | Level 6
Thank you.

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
  • 5 replies
  • 559 views
  • 1 like
  • 3 in conversation