Hi,
I have a library "have" which contains dataset of each day. e.g data20150101,data20150102,data20150105...
and some irrelevant dataset e.g irrelevant1, irrelevant2, irrelevant3..
Sat and Sun dataset are not available. i.e no data20150103, data20150104
I want to create a new dataset "want" combining all the daily files for a month but not those irrelevant dataset,
any possible way to do it automatically? I am now doing it manually with set statement..
Thanks so much for the help!
You could probably use a combination of macro logic, name pattern matching and a control table (s).
If the irrelevant data sets do not begin with DATA201501 then:
Data want;
set data201501: ;
run;
would work to combine all of the, I assume January data sets.
If you are placing the resulting data set in the same library then you may not want to name it data201501<anything> as this code will then append this dataset as well.
I'd go with a macro-based solution that contains a loop with a supplied starting date and end date. I would also use the EXIST function to be able to report on any days where there is no dataset and to add to the SET statement only datasets that exist.
Use dictionary table to pick up these wanted tables.
data data20150101 data20150102 data20150103 data20150104 data20150105 irrelevant1 irrelevant2 irrelevant3; infile cards dsd truncover; input id : $20. i : $20. @; id=compress(id,,'kd'); retain v 1; do until(missing(i)); output; input i : $20. @; end; cards; ID1, ID2,Trait1,Trait2,Trait3 ID3,Trait2,Trait3,Trait5 ID4,Trait5 ID5,Trait1 ;;;; run; proc sql; select memname into : list separated by ' ' from dictionary.members where libname='WORK' and memtype='DATA' and weekday(input(compress(memname,,'kd'), anydtdte.)) in (2:6); quit; data want; length tname $ 40; set &list indsname=indsname; tname=indsname; run;
Xia Keshan
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.