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?
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 201101In 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?
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.
@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.
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?
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!
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.
Ready to level-up your skills? Choose your own adventure.