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
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.