BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
chandan_mishra
Obsidian | Level 7

Hello

 

I want to segregate the dataset based on the unique values of a variable:

 

Ex. The database name is DB. Date is one of the column in MONYY5. format:

 

Date

Oct14

Nov14

Dec14

Jan15

Feb15

Mar15

Apr15

 

data OCT14;
set DB;
where MONTH(Date) EQ 10 and YEAR(Date) Eq 2014;
run;

data NOV14;
set DB;
where MONTH(Date) EQ 11 and YEAR(Date) Eq 2014;
run;

data DEC14;
set DB;
where MONTH(Date) EQ 12 and YEAR(Date) Eq 2014;
run;

This has to be repeated number of times as the unique values in the date column. 

 

The general logic which I am trying to get is:

Data Oct14;

set DB;

where date=Oct14;

run;

 

Just write this one and loop it for all the unique values available in the date column.

 

 

Thanks

Chandan Mishra

 

 

 

 

1 ACCEPTED SOLUTION
2 REPLIES 2
Reeza
Super User

Please read the first part - which is this is usually not needed or recommended and BY group processing is very efficient and simple to program. If after this you find yourself creating many macro loops you know that splitting your data is a bad idea. There are several use cases when this is required - splitting data that is too big for faster processing but that usually means you'll have tens of millions of rows of data. Another usage can be accomplished in other manners that are more efficient, ie a dynamic WHERE statement for PROCs is one option. 

 


@chandan_mishra wrote:

Hello

 

I want to segregate the dataset based on the unique values of a variable:

 

Ex. The database name is DB. Date is one of the column in MONYY5. format:

 

Date

Oct14

Nov14

Dec14

Jan15

Feb15

Mar15

Apr15

 

data OCT14;
set DB;
where MONTH(Date) EQ 10 and YEAR(Date) Eq 2014;
run;

data NOV14;
set DB;
where MONTH(Date) EQ 11 and YEAR(Date) Eq 2014;
run;

data DEC14;
set DB;
where MONTH(Date) EQ 12 and YEAR(Date) Eq 2014;
run;

This has to be repeated number of times as the unique values in the date column. 

 

The general logic which I am trying to get is:

Data Oct14;

set DB;

where date=Oct14;

run;

 

Just write this one and loop it for all the unique values available in the date column.

 

 

Thanks

Chandan Mishra

 

 

 

 


 

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 704 views
  • 1 like
  • 3 in conversation