BookmarkSubscribeRSS Feed
jenny_li
Calcite | Level 5

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!

5 REPLIES 5
LinusH
Tourmaline | Level 20

You could probably use a combination of macro logic, name pattern matching and a control table (s).

Data never sleeps
ballardw
Super User

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.

Reeza
Super User

Adding on to solution, you can use the indsname option if you want to identify the source data set.

Data want;

     set data201501: indsname=source ;

     source=source;

run;

SASKiwi
PROC Star

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.

Ksharp
Super User

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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 5 replies
  • 885 views
  • 1 like
  • 6 in conversation