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 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1119 views
  • 0 likes
  • 3 in conversation