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

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
Meteorite | Level 14

Sorry,I mean 

t20201102

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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