BookmarkSubscribeRSS Feed
uksusu
Calcite | Level 5

I have a list of unique observations that I want to assign a month to for several years

Obs

1

2

3 etc.

I want it to look like

Obs

1 Jan05

1 Feb05

1 Mar05....

.....

1 Jul11

2 Jan05

2 Feb05 and so on.

Can anyone help with the most efficient way of doing this.

Thanks.....

4 REPLIES 4
Jaheuk
Obsidian | Level 7

DATA out(DROP=i);    

DO obs=1 TO 5;      

DO i=0 TO 4;        

date=INTNX('MONTH','01jan2005'd,i,'B');        

OUTPUT;      

END;    

END;    

FORMAT date ddmmyy10.;

RUN;

yonib
SAS Employee

Hi,

In the following program you  need to set the start year and the end_year that you want to use:

data temp;

input obs;

cards;

1

2

3

4

;

run;

%let start_year=2005;

%let end_year=2011;

options symbolgen;

data temp2(drop= j i);

set temp;

do i=&start_year to &end_year;

do j=1 to 12;

month=mdy(j,01,i);

output;

end;

end;

format month mmyyn6.;

run;

art297
Opal | Level 21

I see that others have already shown you how to build a series of consecutive monthly periods, but I have what I think is an equally pressing question: how do you know which date applies to which of your records?

uksusu
Calcite | Level 5

For all of my observations I needed to create an extra row for each month since Jan05 with the obs against it; so each observation would appear 79 times (number of months since Jan05).

I have additional data at obs level but only appearing in certain months; but my customer wants to see all months even if the observation does not have a record against it.

With my original data now I can do a simple merge by obs & date to keep all obs for all months.

I had actually created what I required before posting, but it seemed such a convoluted solution, that I thought there must be an easier way; and there was!

Both options worked fine, but I went with the yonib's in the end.

Thanks to everyone who replied.

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