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

Hello

I want to use this code to split data set into many data sets.

In this example there will be 3 data sets but in real world there will be 1000 data sets so this code work very well.

The only problem is that the data set name is not as I wish.

I want that in data set name I will see the date in format YYYYMMDD.

So I expact to get 3 dats sets:

t2020112 

t2020312 

t2020512 

 

What is the way to do it please?

Data ttt;
format date date9.;
input ID origin $ date :date9.;
cards;
1 EU 01DEC2020'd
2 EU 03DEC2020'd
3 USA 01DEC2020'd
4 USA 05DEC2020'd
5 Africa 05DEC2020'd
6 Africa 01DEC2020'd
;
Run;


%let bysplit=date; 
data have (index = (&bysplit.)) ;   
set ttt ; 
run ;                                                                                                                                   
                                                                                                                                        
data _null_ ;                                                                                                                           
  if _n_ = 1 then do ;                                                                                                                  
    dcl hash h (dataset: "have (obs=0)", multidata:"y") ;                                                                               
    h.definekey ("&bysplit.") ;                                                                                                            
    h.definedata (all: "y") ;                                                                                                           
    h.definedone () ;                                                                                                                   
  end ;                                                                                                                                 
  do until (last.&bysplit.) ;                                                                                                              
    set have ;                                                                                                                          
    by &bysplit. ;                                                                                                                         
    h.add() ;                                                                                                                           
  end ;                                                                                                                                 
  h.output (dataset: catx ("_", "tbl", &bysplit.)) ;                                                                                        
  h.clear() ;                                                                                                                           
run ;   
1 ACCEPTED SOLUTION

Accepted Solutions
japelin
Rhodochrosite | Level 12

You say "format YYYYMMDD", but the data looks like YYYYDDMM.
If it's YYYYDDMM, try using this.

  h.output (dataset: cats ("t", year(&bysplit.),day(&bysplit.),month(&bysplit.)));

 

If you need YYYYMMDD format, replace to this code.

 

  h.output (dataset: cats ("t", put(&bysplit.,yymmddn8.)));

 

 

View solution in original post

3 REPLIES 3
japelin
Rhodochrosite | Level 12

You say "format YYYYMMDD", but the data looks like YYYYDDMM.
If it's YYYYDDMM, try using this.

  h.output (dataset: cats ("t", year(&bysplit.),day(&bysplit.),month(&bysplit.)));

 

If you need YYYYMMDD format, replace to this code.

 

  h.output (dataset: cats ("t", put(&bysplit.,yymmddn8.)));

 

 

Ronein
Onyx | Level 15

Sorry,I mean 

t20201102

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 3 replies
  • 1009 views
  • 1 like
  • 3 in conversation