BookmarkSubscribeRSS Feed
SasStatistics
Pyrite | Level 9

I have a SAS data set, let's call it MyDataTable, of the following schematic form (it has like 10 millions rows so all months for the last 20 years are covered): 

Observation  Period 
1 201101
2 201102
3 201103
4 201104
5 201105
6 201106
7 201107
8 201108
9 201109
10 201110
11 201111
12 201112

 

The Period column has the format: $6.  

Now, I would dynamically like to extract some observations each month in a table called MyDesiredData. So for example: 

Assuming now we stand in year 2011: 
In january I would like to extract observation 1 with period 201101

In februari I would like to extract observation 2 with period 201102

.

 

My try was something like: 

data MyDesiredData; 
	set MyDataTable(where=(period=put(today(),yymn6.))); 
run; 

Any suggestions? 

5 REPLIES 5
Reeza
Super User

I would have expected that to work, what error did you get?

 


@SasStatistics wrote:

I have a SAS data set, let's call it MyDataTable, of the following schematic form (it has like 10 millions rows so all months for the last 20 years are covered): 

Observation  Period 
1 201101
2 201102
3 201103
4 201104
5 201105
6 201106
7 201107
8 201108
9 201109
10 201110
11 201111
12 201112

 

The Period column has the format: $6.  

Now, I would dynamically like to extract some observations each month in a table called MyDesiredData. So for example: 

Assuming now we stand in year 2011: 
In january I would like to extract observation 1 with period 201101

In februari I would like to extract observation 2 with period 201102

.

 

My try was something like: 

data MyDesiredData; 
	set MyDataTable(where=(period=put(today(),yymn6.))); 
run; 

Any suggestions? 


 

PaigeMiller
Diamond | Level 26
data MyDesiredData; 
	set MyDataTable(where=(period=put(today(),yymn6.))); 
run; 

Maxim 2: Read the Log

 

Given the code you have posted, the log should indicate the exact problem.

--
Paige Miller
SasStatistics
Pyrite | Level 9
I used the reply you posted before, why did you remove it? Wanted to accept the answer.
PaigeMiller
Diamond | Level 26

@SasStatistics wrote:
I used the reply you posted before, why did you remove it? Wanted to accept the answer.

There are better answers ... as I said, read the log, then figure out what the problem is ... the log is very clear.

--
Paige Miller
Reeza
Super User

Your original code should have worked, the other answer is actually not the preferred method, your code is the preferred method.
So what error did you get with the original code?

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 746 views
  • 0 likes
  • 3 in conversation