Help using Base SAS procedures

Loop and copy sas data files from one directory and to another with obs=0

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

Loop and copy sas data files from one directory and to another with obs=0

Hi All!

I am a SAS newbie and as such was given a simple request for which I am having a lot of trouble.

Long story short: I want to pass in an absolute directory, ant then copy all *.sas7bdat files to another directory (hardcoded in the program) with obs=0. So only the metadata. Once I have this I can use perl or bash scripting to rsync these files to another server. This is what I have that works. It is for a single file.

libname data '/data/prod/201004_201403_12_3_3'; /* <-- Search for *.sas7bdat */

libname metadata '/apps/ntzload/nzsas'; /*  <-- Copy them here with 0 obs */

data  metadata.allsumip; /* <-- Name of one of the files in the lib "data"

    set  data.allsumip(obs=0);

run;

I've tried to scour the internet and 4 SAS books to find simple looping solutions. I can get a listing of files in a directory, I can't seem to instruct sas to copy them to another directory with ZERO obs. I get error after error and instead of beating my head into a wall - I thought I'd grovel for assistance.

Thank you in advance for your help and patience.


Accepted Solutions
Solution
‎10-07-2014 03:11 PM
Super User
Posts: 17,819

Re: Loop and copy sas data files from one directory and to another with obs=0

Use option obs=0 if all the datasets in a library.

option obs=0;

proc datasets library=test;

copy in=test out=tests;

run;quit;

option obs=max;


For select names only:

proc sql;

create table dsetlist as

select memname into :memlist from sashelp.vtable

where libname = 'TEST';

quit;


option obs=0;

proc datasets library=test;

copy in=test out=tests;

select &memlist.;

run;quit;

option obs=max;



View solution in original post


All Replies
Solution
‎10-07-2014 03:11 PM
Super User
Posts: 17,819

Re: Loop and copy sas data files from one directory and to another with obs=0

Use option obs=0 if all the datasets in a library.

option obs=0;

proc datasets library=test;

copy in=test out=tests;

run;quit;

option obs=max;


For select names only:

proc sql;

create table dsetlist as

select memname into :memlist from sashelp.vtable

where libname = 'TEST';

quit;


option obs=0;

proc datasets library=test;

copy in=test out=tests;

select &memlist.;

run;quit;

option obs=max;



New Contributor
Posts: 2

Re: Loop and copy sas data files from one directory and to another with obs=0

Thank you so much! Smiley Happy:smileyplus:

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 191 views
  • 0 likes
  • 2 in conversation