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 ;
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.)));
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.)));
t2020112
Is this 2020-01-12 or 2020-11-02, or a typing mistake?
Sorry,I mean
t20201102
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!
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.